本文介绍了Golang:安装目录错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有错误: go install:no安装目录位置/ Users / xwilly / Dropbox / go / project / src outside GOPATH 我在OS X上使用版本1.1。 我可以建立& 我的环境: GOPATH = / Users / xwilly / Dropbox / go / project PATH = / Library / Frameworks / Python.framework / Versions / 2.7 / bin:/ usr / bin:/ bin:/ usr / sbin:/ sbin:/ usr / local / bin:/ usr / local / go / bin:/ Users / xwilly / Dropbox / go / project / bin 项目树: / Users / xwilly / Dropbox / go / project bin pkg src 我可以毫无错误地构建: ..:src xwilly $ go build test.go ::src xwilly $ go安装test.go go install:没有安装目录/ Users / xwilly / Dropbox / go / project / src在GOPATH之外的位置 这里是一个简单的例子: xwilly $ cat test.go package main import( fmt) func main(){ fmt.Println(Bonjour)} xwilly $ go run test.go Bonjour xwilly $ go安装测试。去去安装:没有安装目录的位置/ Users / xwilly / Dropbox / go / project / src / learning GOPATH 解决方案 您的目录结构错误。您正试图安装一个命令( package main )。它应该位于以命令命名的源目录中。请参阅上面的 quux 命令。 在您的情况下,假设您的命令将被命名为 billy 。 $ mkdir -p / Users / xwilly / Dropbox / go / project / src / billy 它位于 GOPATH 。将 test.go 文件移动到此目录。运行 $ go安装billy 命令 billy 应该被安装在中,除非你已经设置 GOBIN / p> / Users / xwilly / Dropbox / go / project / bin 内的$ p> 目录,该目录应位于 PATH 。 I have the error:go install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATHI'm using go version 1.1 on OS X.I can build & run but can't install packages.My environment:GOPATH=/Users/xwilly/Dropbox/go/projectPATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/go/bin:/Users/xwilly/Dropbox/go/project/binProject tree:/Users/xwilly/Dropbox/go/projectbinpkgsrcI can build without error:..:src xwilly$ go build test.go..:src xwilly$ go install test.gogo install: no install location for directory /Users/xwilly/Dropbox/go/project/src outside GOPATHHere is a simple example:xwilly$ cat test.gopackage mainimport ( "fmt")func main() { fmt.Println("Bonjour")}xwilly$ go run test.goBonjourxwilly$ go install test.gogo install: no install location for directory /Users/xwilly/Dropbox/go/project/src/learning outside GOPATH 解决方案 Your directory structure is wrong. You are trying to install a command (package main). It should be in a source directory named after your command. See the quux command above.In your case, assume your command is going to be named billy.$ mkdir -p /Users/xwilly/Dropbox/go/project/src/billywhich is inside your GOPATH. Move your test.go file to this directory. Run$ go install billyThe command billy should, unless you have set GOBIN, be installed in the /Users/xwilly/Dropbox/go/project/bindirectory inside your GOPATH, which should be in your PATH. 这篇关于Golang:安装目录错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-04 23:12