dqz84361326 2015-03-04 15:03 采纳率: 0%
浏览 1085
已采纳

我已经设置了我的$ GOPATH,但是它不起作用

$ sudo go get -u github.com/golang/lint/golint
package github.com/golang/lint/golint: cannot download, $GOPATH not set. For more details see: go help gopath

I have set my $GOPATH: (in ~/.bash_profile on my Mac) export GOPATH=$HOME/gocode

And my go env:

$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wildcat/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fno-common"
CXX="g++"
CGO_ENABLED="1"

What's the problem?

  • 写回答

2条回答 默认 最新

  • douzhi9921 2015-03-04 15:07
    关注

    The issue is that you are using sudo: it will use the root environment variable instead of the ones of your account.

    You shouldn't need to use sudo, as I mentioned in "How to set GOPATH in Mac OS X 10.10":

    • sudo has a default policy of resetting the Environment and setting a secure path
    • unless you use the more complex sudo -E bash -c 'go get github.com/golang/lint/golint'):

    For now, this should be enough:

    go get -u github.com/golang/lint/golint
    

    The OP adds a different go get command in the comments:

    go install golang.org/x/tools/cmd/cover: 
      open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied 
    

    That one would be using $GOTOOLDIR (set in your case to "/usr/local/go/pkg/tool/darwin_amd64")

    As documented in "Permission denied error for 'go.tools'", running sudo -s then the go get command should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度