Go安装通常会在GOPATH之外没有安装目录 [英] Go install always fails no install directory outside GOPATH
问题描述
〜/ SRC /复statsd-客户机GT; echo $ GOPATH
/ Users / me / gopath
〜/ src / go-statsd-client> echo $ GOROOT
/usr/local/Cellar/go/1.1.1\
〜/ src / go-statsd-client> go安装
go安装:没有安装目录/ Users / me / src / go-statsd-client GOPATH以外的位置
无论项目在哪种结构下都会出现相同的消息。 Go build的功能完美。
这是我的去env
GOARCH =amd64
GOBIN =
GOCHAR =6
GOEXE =
GOHOSTARCH =amd64
GOHOSTOS =darwin
GOOS =darwin
GOPATH =/ Users / me / gopath
GORACE =
GOROOT =/ usr /local/Cellar/go/1.1.1
GOTOOLDIR =/ usr / local / Cellar / go / 1.1.1 / pkg / tool / darwin_amd64
CC =gcc
GOGCCFLAGS = - g -O2 -fPIC -m64 -pthread -fno-common
CGO_ENABLED =1
这是在Mac OSX Mountain Lion上,并安装了自制软件。 当您不提供参数到 go install
,它默认尝试在当前目录中安装软件包。错误消息告诉你它不能这样做,因为当前目录不是你的 $ GOPATH
的一部分。
您可以:
$ GOPATH
到您的$ HOME export GOPATH = $ HOME
)。
$ GOPATH
( mv〜/ src / go-statsd-client / User / me / gopath
)。
然后,进入 go-statsd-client
目录并键入 go install
会起作用,所以在文件系统的任何地方输入去安装go-statsd-client
。构建的二进制文件将进入 $ GOPATH / bin
。
作为一个无关的建议,您可能想要命名空间包含域名,以避免名称冲突(例如 github.com/you/go-statsd-client
,如果这是您持有源代码的地方)。
~/src/go-statsd-client> echo $GOPATH
/Users/me/gopath
~/src/go-statsd-client> echo $GOROOT
/usr/local/Cellar/go/1.1.1\
~/src/go-statsd-client> go install
go install: no install location for directory /Users/me/src/go-statsd-client outside GOPATH
No matter what structure the project is in this always fails with the same message. Go build works perfectly.
Here is my go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/me/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.1.1"
GOTOOLDIR="/usr/local/Cellar/go/1.1.1/pkg/tool/darwin_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
CGO_ENABLED="1"
This is on Mac OSX Mountain Lion and go was installed with homebrew.
When you provide no arguments to go install
, it defaults to attempting to install the package in the current directory. The error message is telling you that it cannot do that, because the current directory isn't part of your $GOPATH
.
You can either:
- Define
$GOPATH
to your $HOME (export GOPATH=$HOME
). - Move your source to within the current
$GOPATH
(mv ~/src/go-statsd-client /User/me/gopath
).
After either, going into the go-statsd-client
directory and typing go install
will work, and so will typing go install go-statsd-client
from anywhere in the filesystem. The built binaries will go into $GOPATH/bin
.
As an unrelated suggestion, you probably want to namespace your package with a domain name, to avoid name clashing (e.g. github.com/you/go-statsd-client
, if that's where you hold your source code).
这篇关于Go安装通常会在GOPATH之外没有安装目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!