beego - linux环境下golang安装第三方库的时候出错,求解决办法
高洛峰
高洛峰 2017-04-17 13:10:57
0
4
694

使用如下方式安装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"

该怎么解决呢?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
阿神

Referring to the above answer, I explored it myself and found a more complete solution, as follows:

go install unicode/utf8: open /opt/go/pkg/linux_amd64/unicode/utf8.a: permission denied

The reason for this error is that I copied the golang compressed package directly to the /opt directory. All source codes were not compiled. I should first switch to the /opt/go/src directory and execute sudo Compile the ./make.bash script. After completion, use the following command to install beego without error:

go get github.com/astaxie/beego

In this case, when you execute the following command to install the bee tool, you will be prompted with insufficient permissions:

go get github.com/beego/bee

go install github.com/beego/bee: open /opt/go/bin/bee: permission denied

My solution to this is to first switch to the /opt directory and execute the following command to modify the permissions of the go folder:

sudo chmod -R 777 go/

In this way, the bee tool can be installed normally.

左手右手慢动作

Is your environment configuration printed out through go env? Also, is your golang installed through package management or downloaded and installed? It feels like you installed it through package management, or there are two golangs on the machine. Of course, this is also my guess

Update: Another possibility is that your environment variables are set under .bash.profile in the user directory instead of /etc/profile, which only takes effect for the current user. When you sudo, you cannot get goroot, so access the default goroot

Ty80

go get github.com/astaxie/beego Will clone first and then build. When building, you need to find the go installation directory through GOROOT,

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

This error is because the environment variable was not found, and then the default search /usr/local/go was not found, so an error was reported,

Solution: First source check the configuration file, then echo $GOROOT check the result

大家讲道理

I think if you can put the source code in the user directory and compile it, there should be no permission issues.
Or you can install it directly using apt-get or yum.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!