‘go install’ 尝试安装到 /usr/lib/go 而不是我的 GOPATH。权限被拒绝

huangapple go评论105阅读模式
英文:

'go install' trying to install to /usr/lib/go instead of my GOPATH. Permission denied

问题

我在Linux Mint 14上安装Go时遇到了一些困难。我有一个文件夹($HOME/develop/gocode),其中包含binpkgsrc文件夹,作为我的GOPATH,并且已经正确设置了GOPATH环境变量。我尝试使用go get命令安装一个特定的GitHub存储库(https://github.com/jbarham/primegen.go),但是Go给我报错:stat github.com/jbarham/primegen.go: no such file or directory(我认为是因为存储库以.go结尾)。好吧,我手动克隆了它,但是当我尝试在该存储库中安装两个可执行文件之一(两个都不起作用,但我首先尝试安装primespeed)时,我遇到了以下错误:

$ cd $GOPATH/src/github.com/jbarham/primegen.go/primespeed
$ go install
go install github.com/jbarham/primegen.go: mkdir /usr/lib/go/pkg/linux_amd64/github.com: permission denied

为什么Go要尝试在那里安装包?我已经明确设置了我的GOPATH变量,但它仍然尝试将包安装到/usr/local中。

我不确定这是否有帮助,但这里还有一些关于版本和环境的其他输出:

$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="amd64"
GOCHAR="6"
GOOS="linux"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
$ go version
go version go1.0.2
英文:

I have had some difficulties getting Go up and running correctly on Linux Mint 14. I have a folder ($HOME/develop/gocode) with bin, pkg and src folders as my GOPATH and have the GOPATH environment variable set properly there. I tried installing a certain github repository using go get (https://github.com/jbarham/primegen.go) but Go gave me the error: stat github.com/jbarham/primegen.go: no such file or directory (I think because the repository ends in .go.) Fine, I just cloned it manually, but then when I try to go install one of two executables in that repository (neither one works, but I tried installing primespeed first) I get the following error:

$ cd $GOPATH/src/github.com/jbarham/primegen.go/primespeed
$ go install
go install github.com/jbarham/primegen.go: mkdir /usr/lib/go/pkg/linux_amd64/github.com: permission denied

Why is go trying to install the package there? I've explicitly set my GOPATH variable, and yet it is trying to install packages to /usr/local instead.

I'm not sure if it will help, but here is some other output regarding version and environment:

$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="amd64"
GOCHAR="6"
GOOS="linux"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
$ go version
go version go1.0.2

答案1

得分: 8

尝试一下。

英文:
export GOPATH=$HOME/go

export GOBIN=$HOME/go/bin

try it.

答案2

得分: 5

  1. 您的GOPATH可能没有被导出。
  2. 是的,具有.go扩展名的存储库无法通过go get获取。

广告1.(最好放在.bashrc或等效文件中):

$ export GOPATH=$HOME # 仅作为示例

广告2.(最好提出一个问题来讨论这个荒谬的存储库名称):

$ mkdir -p $GOPATH/src/github.com/jbarham
$ cd $GOPATH/src/github.com/jbarham
$ git clone https://github.com/jbarham/primegen.go.git
$ cd primegen.go
$ go install
英文:
  1. Your GOPATH is probably not exported.
  2. Yes, repositories having a .go extension are not 'go gettable'.

Ad 1. (better put into .bashrc or equivalent):

$ export GOPATH=$HOME # just an example

Ad 2. (better raise an issue about the nonsensical repository name):

$ mkdir -p $GOPATH/src/github.com/jbarham
$ cd $GOPATH/src/github.com/jbarham
$ git clone https://github.com/jbarham/primegen.go.git
$ cd primegen.go
$ go install

答案3

得分: 0

我遇到了同样的问题,但发现对于某些仓库,你需要明确添加GOPATH的导出。例如,从我的GOPATH中:

cd $GOPATH
export GOPATH=$PWD && go get -d github.com/nsf/gocode

我猜你可以完全避免这个问题,如果你给它起一个别名:

alias goget='cd $GOPATH; export GOPATH=$PWD && go get' 

这并不完美,奇怪的是export GOPATH=$GOPATH不起作用。由于某种原因,一些仓库会将GOPATH重置为$HOME并尝试以不同的用户身份执行。我猜测是go get方法中的某些开发代码干扰了调用。【只是猜测,请不要引用我】

英文:

I had the same issue, but found that, the for some repos you need to specifically add the export GOPATH. for example from my GOPATH

cd $GOPATH
export GOPATH=$PWD && go get -d github.com/nsf/gocode

you could avoid it all together I guess, if you alias it:

alias goget='cd $GOPATH; export GOPATH=$PWD && go get' 

This isn't perfect and oddly enough export GOPATH=$GOPATH does not work.
for some reason some repos are resetting the GOPATH to $HOME and trying to execute as a different user.
My guess is some development code somewhere in the go get method that is messing with the calls. [just a hunch, don't quote me]

huangapple
  • 本文由 发表于 2013年6月4日 12:12:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/16909689.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定