go安装总是尝试使用GOROOT,GOPATH没有在go env下列出 [英] go install always attempts to use GOROOT and GOPATH is not listed under go env
问题描述
我对 GOPATH
有一个相当令人沮丧的问题,尽管它被设置在 .profile
中,在调用 go env
时没有出现,并且不会影响 go install
目标位置。
I'm having a quite frustrating problem with the GOPATH
, which, despite being set in .profile
, is not appearing when invoking go env
, and does not appear to be affecting the go install
target location.
我试图使用 go install
来安装软件包,并且得到这个错误,这清楚地表明它正在尝试安装在 / usr / lib / go
中,而不是 / home / me / dev / go
。
I'm attempting to use go install
to install packages, and am getting this error, which clearly shows that it is attempting to install in /usr/lib/go
, rather than the intended directory of /home/me/dev/go
.
$ go install github.com/songgao/colorgo
go install github.com/songgao/go.pipeline: mkdir /usr/lib/go/pkg/linux_386/github.com: permission denied
go env
给出以下结果。
$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"
但是最确定的是 设置。
But it most certainly is set.
$ echo $GOPATH
/home/me/dev/go
更新: strong>我已经在〜/ .profile
中导出了GOPATH并找到它,但我仍然遇到同样的问题。
Update: I have exported GOPATH in ~/.profile
and sourced it, but I'm still having the same problem.
$ export GOPATH=/home/me/dev/go
$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"
再次更新:自我升级到go1.1beta2。我不确定是哪里出了问题,因为 GOPATH
似乎设置正确,但现在所有的显然都在工作。
Update again: This problem has ceased since I upgraded to go1.1beta2. I'm not sure what was wrong, because GOPATH
appeared to be set correctly, but it's all apparently working now.
推荐答案
$ mkdir -p $HOME/dev/go/src
$ mkdir -p $HOME/dev/go/bin
在 $ HOME /中。 profile
:
export GOPATH=$HOME/dev/go:
export PATH=$PATH:$HOME/dev/go/bin
然后重新启动或注销并登录。
Then reboot or log out and log in.
只要您登录,在运行之前,运行:
As soon as you have logged in, before anything else, run:
$ env | grep -i '^GO'
GOPATH=/home/me/dev/go
$ cat $HOME/.profile
你会得到什么输出?
这篇关于go安装总是尝试使用GOROOT,GOPATH没有在go env下列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!