Cannot start go install: no installation location for a directory outside of GOPATH

When I try to start 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 installand get the following:

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

Here's mine 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 do this all morning.

+4
source share
1 answer

There seems to be a problem with the resolution, the change in ownership $GOPATHshould be fixed.

sudo chown -R $USER $GOPATH

I assume that you somehow installed something as root, which changed the resolution $GOPATH/pkg.

+6
source

All Articles