Go install copying permission denied

9.8k Views Asked by At

When running go install on my cmd folder I get the error:

go install cmd/go: copying 
/var/folders/wh/9y99138n2w1bvcwxz3tbb8zw0000g
n/T/go-build195667123/b150/exe/a.out: open 
/usr/local/go/bin/go: permission denied

It looks like my env variables are set correctly:

GOCACHE="/Users/<USER>/Library/Caches/go-build"
GOENV="/Users/<USER>/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/<USER>/src/unbias"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"

Here's my directory of my current project: which is inside my go path: /Users/<USER>/src/unbias

enter image description here

Since it looks like the permission error is not in my project but in my go install path, I am not sure if I should change ownership of such files.

total 37032
drwxr-xr-x   4 root  wheel   128B Jul 16 15:53 .
drwxr-xr-x  20 root  wheel   640B Jul 16 15:29 ..
-rwxr-xr-x   1 root  wheel    15M Jul 16 15:52 go
-rwxr-xr-x   1 root  wheel   3.4M Jul 16 15:53 gofmt

My go.mod is also:

module cmd

go 1.14
1

There are 1 best solutions below

6
On

It means that either <PATH_TO>/cmd permission is not writable or $GOPATH/pkg/cmd/go is not readable for your User.

You may:

  1. use sudo chmod -R 777 <PATH_TO>/cmd
  2. using govendor or go mod if it's outside of GOPATH.
  3. try to create inside $GOPATH instead (you haven't stated if <PATH_TO>/cmd inside $GOPATH
  4. If <PATH_TO>/cmd is writable, use sudo for now and change the ownership to <User> again by chown

Check the permission on <PATH_TO>/cmd or $GOPATH/pkg/cmd/go again by ls -lah <PATH_TO>/cmd, it should be readable and writable.