go install: no install location for directory /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 install test.go go install: no install location for directory /Users/xwilly/DropBox/go/project/src outside GOPATH
这是一个简单的例子:
xwilly$ cat test.go package main import ( "fmt" ) func main() { fmt.Println("Bonjour") } xwilly$ go run test.go Bonjour xwilly$ go install test.go go install: no install location for directory /Users/xwilly/DropBox/go/project/src/learning outside GOPATH
07000
07001
Each directory listed in
GOPATH
must have a prescribed structure:The
src/
directory holds source code. The path below ‘src
‘ determines
the import path or executable name.The
pkg/
directory holds installed package objects. As in the Go tree,
each target operating system and architecture pair has its own
subdirectory ofpkg
(pkg/GOOS_GOARCH
).If
DIR
is a directory listed in theGOPATH
,a package with source in
DIR/src/foo/bar can be imported as “foo/bar
” and has its compiled form
installed to “DIR/pkg/GOOS_GOARCH/foo/bar.a
“.The
bin/
directory holds compiled commands. Each command is named for
its source directory,but only the final element,not the entire path.
That is,the command with source inDIR/src/foo/quux
is installed into
DIR/bin/quux,notDIR/bin/foo/quux
. Thefoo/
is stripped so that you
can addDIR/bin
to yourPATH
to get at the installed commands. If the
GOBIN
environment variable is set,commands are installed to the
directory it names instead ofDIR/bin
.Here’s an example directory layout:
06000
你的目录结构是错误的。您正在尝试安装一个命令(package main)。它应该在命令中命名的源目录中。请参见上面的quux命令。
在你的情况下,假设你的命令将被命名为比利。
$ mkdir -p /Users/xwilly/DropBox/go/project/src/billy
在你的GOPATH里面。将您的test.go文件移动到此目录。跑
$ go install billy
命令比利应该,除非你设置GOBIN,安装在
/Users/xwilly/DropBox/go/project/bin
您的GOPATH中的目录,它应该在您的PATH中。