转到安装失败,并显示以下错误:GOPATH外部的目录xxx没有安装位置 [英] Go install fails with error: no install location for directory xxx outside GOPATH
问题描述
~/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.
这是我的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"
这是在Mac OSX Mountain Lion上,并且安装了自制软件.
This is on Mac OSX Mountain Lion and go was installed with homebrew.
推荐答案
当不向go install
提供任何参数时,默认情况下将尝试在当前目录中安装软件包.错误消息告诉您它不能执行此操作,因为当前目录不属于您的$GOPATH
.
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
.
您可以:
- 将
$GOPATH
定义为$ HOME(export GOPATH=$HOME
). - 将源移动到当前
$GOPATH
(mv ~/src/go-statsd-client /User/me/gopath
)内.
- Define
$GOPATH
to your $HOME (export GOPATH=$HOME
). - Move your source to within the current
$GOPATH
(mv ~/src/go-statsd-client /User/me/gopath
).
在其中一个之后,进入go-statsd-client
目录并键入go install
将起作用,从文件系统中的任何位置键入go install go-statsd-client
也将起作用.生成的二进制文件将进入$GOPATH/bin
.
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
.
作为不相关的建议,您可能希望使用域名对软件包进行命名空间,以避免名称冲突(例如github.com/you/go-statsd-client
,如果您在其中保存源代码).
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).
这篇关于转到安装失败,并显示以下错误:GOPATH外部的目录xxx没有安装位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!