linux环境下golang安装第三方库的时候出错,求解决办法


使用如下方式安装beego的时候出错


 go get github.com/astaxie/beego

错误信息:

go install unicode/utf8: open /opt/go/pkg/linux_amd64/unicode/utf8.a: permission denied
go install unicode: open /opt/go/pkg/linux_amd64/unicode.a: permission denied
go install math: open /opt/go/pkg/linux_amd64/math.a: permission denied
go install sort: open /opt/go/pkg/linux_amd64/sort.a: permission denied
go install hash: open /opt/go/pkg/linux_amd64/hash.a: permission denied
go install unicode/utf16: open /opt/go/pkg/linux_amd64/unicode/utf16.a: permission denied
go install crypto/subtle: open /opt/go/pkg/linux_amd64/crypto/subtle.a: permission denied
go install container/list: open /opt/go/pkg/linux_amd64/container/list.a: permission denied
go install internal/syscall: open /opt/go/pkg/linux_amd64/internal/syscall.a: permission denied
go install time: open /opt/go/pkg/linux_amd64/time.a: permission denied

然后我在命令前加了一个sudo,然后提示

go: cannot find GOROOT directory: /usr/local/go

我的golang环境配置如下:

GOARCH="amd64"
GOBIN="/opt/go/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/buchenglei/workspace/golang"
GORACE=""
GOROOT="/opt/go"
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

该怎么解决呢?

Linux beego go

cv10800 9 years, 10 months ago

你这个环境配置是通过 go env 打印出来的么?还有就是你的golang是软件包管理安装的,还是下载安装的,感觉你这个好像是由于用包管理安装的原因,或者说机器上存在两个golang引起的,当然这也是我的猜测

更新:还有一种可能是你的环境变量设置在用户目录下的.bash.profile下,而不是/etc/profile下,只对当前用户生效。当你sudo 时,就拿不到goroot,所以访问默认的goroot

记忆Edda answered 9 years, 10 months ago

Your Answer