search

Home  >  Q&A  >  body text

beego - 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"

该怎么解决呢?

高洛峰高洛峰2867 days ago742

reply all(4)I'll reply

  • 阿神

    阿神2017-04-17 13:12:57

    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.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:12:57

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:12:57

    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

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:12:57

    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.

    reply
    0
  • Cancelreply