自定义GOPATH下安装godep失败

自定义GOPATH下安装godep失败

我的环境变量是这样的:

export GOROOT=/usr/local/go
export GOPATH=/Users/addo/Workspaces/go_w
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN

使用下面的命令安装报错:

go get -v github.com/tools/godep

github.com/tools/godep (download) github.com/tools/godep/vendor/github.com/pmezard/go-difflib/difflib github.com/tools/godep/vendor/github.com/kr/fs github.com/tools/godep/vendor/github.com/kr/text github.com/tools/godep/vendor/golang.org/x/tools/go/vcs github.com/tools/godep/vendor/github.com/kr/pretty github.com/tools/godep go install github.com/tools/godep: open /usr/local/go/bin/godep: permission denied

默认是安装到$GOBIN目录下, 权限不够.

使用:

sudo go get -v github.com/tools/godep

sudo go get -v github.com/tools/godep github.com/tools/godep (download) created GOPATH=/Users/addo/go; see ‘go help gopath’ github.com/tools/godep/vendor/github.com/kr/fs github.com/tools/godep/vendor/github.com/kr/text github.com/tools/godep/vendor/github.com/pmezard/go-difflib/difflib github.com/tools/godep/vendor/golang.org/x/tools/go/vcs github.com/tools/godep/vendor/github.com/kr/pretty github.com/tools/godep

$GOBIN并没有找到godef. 输出提示created GOPATH=/Users/addo/go; . 因为sudo的时候找不到GOPATH变量, 便重新创建了目录.

解决方案一:

  1. 临时修改GOBIN: export GOBIN=$GOPATH/bin
  2. 运行go get github.com/tools/godep
  3. 将生成的godef复制到GOROOT/bin
  4. 回滚修改export GOBIN=$GOROOT/bin; export PATH=$PATH:$GOBIN

解决方案二:

修改GOROOT/bin的属组属主, 安全性问题, 不推荐.

(转载本站文章请注明作者和出处乱世浮生,请勿用于任何商业用途)

comments powered by Disqus

目录

推荐阅读