3

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.

Oscar Swanros
  • 19,767
  • 5
  • 32
  • 48
  • possible duplicate of [Go install always fails no install directory outside GOPATH](http://stackoverflow.com/questions/18149601/go-install-always-fails-no-install-directory-outside-gopath) – Daniel Williams Aug 19 '14 at 19:07
  • 1
    @DanielWilliams that's a permission problem, not a dup of that question you linked. – OneOfOne Aug 19 '14 at 19:31
  • Don't use sudo when installing go packages. It will always continue to trip you up. – JimB Aug 19 '14 at 19:34
  • @JimB I know I shouldn't use ``sudo``, but I had to try it due to the error description. Thanks! – Oscar Swanros Aug 19 '14 at 20:29

1 Answers1

6

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.

OneOfOne
  • 95,033
  • 20
  • 184
  • 185