dqqs64238
dqqs64238
2017-05-25 18:52

当“ go env”显示设置正确时,为什么“ go get”找不到$ 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条回答

  • dragon188199 dragon188199 4年前

    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.

    点赞 评论 复制链接分享