自定义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
变量, 便重新创建了目录.
解决方案一:
- 临时修改
GOBIN
:export GOBIN=$GOPATH/bin
- 运行
go get github.com/tools/godep
- 将生成的godef复制到
GOROOT/bin
下 - 回滚修改
export GOBIN=$GOROOT/bin; export PATH=$PATH:$GOBIN
解决方案二:
修改GOROOT/bin
的属组属主, 安全性问题, 不推荐.