无法运行go install:GOPATH之外的目录没有安装位置。

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

Unable to run go install: no install location for directory outside GOPATH

问题

当我尝试运行go install时,我得到以下错误:

go install golang-book/chapter11/math: mkdir /Users/Swanros/Go/pkg/darwin_amd64: permission denied

然后我尝试sudo go install,得到以下错误:

go install: no install location for directory /Users/Swanros/Go/src/golang-book/chapter11/math outside GOPATH

这是我的go env

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Swanros/Go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

echo $GOPATH 输出:

/Users/Swanros/Go

我错过了什么?我一整个早上都在处理这个问题。

英文:

When I try to run go install I get the following:

go install golang-book/chapter11/math: mkdir /Users/Swanros/Go/pkg/darwin_amd64: permission denied

Then I try sudo go install and get the following:

go install: no install location for directory /Users/Swanros/Go/src/golang-book/chapter11/math outside GOPATH

Here's my go env:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/Swanros/Go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

echo $GOPATH outputs:

/Users/Swanros/Go

What am I missing? I've been dealing with this all morning.

答案1

得分: 6

看起来是一个权限问题,更改$GOPATH的所有权应该可以解决。

sudo chown -R $USER $GOPATH

我猜你可能以 root 用户身份安装了某些东西,导致了$GOPATH/pkg的权限变化。

英文:

It looks like a permission problem, changing the ownership on $GOPATH should fix it.

sudo chown -R $USER $GOPATH

I'm guessing that you somehow installed something as root that changed the permission of $GOPATH/pkg.

huangapple
  • 本文由 发表于 2014年8月20日 03:01:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/25391051.html
匿名

发表评论

匿名网友

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

确定