为什么 “go get” 在 “go env” 显示 GOPATH 设置正确时找不到它?

huangapple go评论76阅读模式
英文:

Why can't "go get" find $GOPATH when "go env" shows it's set correctly?

问题

我正在尝试在我的Macbook Pro上安装go版本go1.6.4 darwin/amd64。

尽管已经设置了$GOPATH,但我似乎无法使用'go get'下载远程包。
$ go env

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Bryan/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

$ ls /Users/Bryan/go

total 24
drwxr-xr-x   6 Bryan  staff   204 May 23 12:13 .
drwxr-xr-x+ 73 Bryan  staff  2482 May 25 11:20 ..
-rw-r--r--@  1 Bryan  staff  8196 May 24 15:11 .DS_Store
drwxr-xr-x  32 Bryan  staff  1088 Mar 28 14:21 bin
drwxr-xr-x   3 Bryan  staff   102 Mar 28 14:21 pkg
drwxr-xr-x  10 Bryan  staff   340 May 25 11:18 src

Bryan@Bryans-MacBook-Pro Thu May 25 12:23:24 ~/go/src/skincarereview
$ sudo go get

Password:
package google.golang.org/appengine: 无法下载,未设置$GOPATH。有关详细信息,请参阅:go help gopath
package google.golang.org/appengine/datastore: 无法下载,未设置$GOPATH。有关详细信息,请参阅:go help gopath
英文:

I'm attempting to get go version go1.6.4 darwin/amd64 installed on my Macbook Pro.

I can't seem to download remote packages with 'go get' despite having the $GOPATH set.
$ go env

GOARCH="amd64"  
GOHOSTARCH="amd64"  
GOHOSTOS="darwin"  
GOOS="darwin"  
GOPATH="/Users/Bryan/go"  
GORACE=""  
GOROOT="/usr/local/go"  
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"  
GO15VENDOREXPERIMENT="1"  
CC="clang"  
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"  
CXX="clang++"  
CGO_ENABLED="1"  

$ ls /Users/Bryan/go

total 24  
drwxr-xr-x   6 Bryan  staff   204 May 23 12:13 .  
drwxr-xr-x+ 73 Bryan  staff  2482 May 25 11:20 ..  
-rw-r--r--@  1 Bryan  staff  8196 May 24 15:11 .DS_Store  
drwxr-xr-x  32 Bryan  staff  1088 Mar 28 14:21 bin  
drwxr-xr-x   3 Bryan  staff   102 Mar 28 14:21 pkg  
drwxr-xr-x  10 Bryan  staff   340 May 25 11:18 src  

Bryan@Bryans-MacBook-Pro Thu May 25 12:23:24 ~/go/src/skincarereview
$ sudo go get

Password:  
package google.golang.org/appengine: cannot download, $GOPATH not set. For more details see: go help gopath  
package google.golang.org/appengine/datastore: cannot download, $GOPATH not set. For more details see: go help gopath

答案1

得分: 4

你的$GOPATH设置在你的用户$PATH中,但是你正在使用sudo来调用go get,而sudo有自己独立的$PATH

为了说明这一点,尝试运行sudo go env,你会看到它们之间的差异。

不过,你可能本来就不应该使用sudo go get

英文:

Your $GOPATH is set in your user $PATH, but you are envoking go get using sudo which has its own $PATH different from yours.

To illustrate, try sudo go env and you will see the difference.

You probably shouldn't be using sudo go get anyway though.

huangapple
  • 本文由 发表于 2017年5月26日 02:52:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/44187856.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定