Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go build -i cause open /usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied

Tags:

go

I build my project use

go build -i -v -o ./bin/demo-api .

get result

go build runtime/cgo: copying /Users/hrbc/Library/Caches/go-build/63/63a132c80210b5c7b4f4ed9a902aaec712c42b15e23aa2c1b1778e2f85165d04-d: open /usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied

It work good without -i option.Is there anything I can do to resolve this problem?

go version go1.14 darwin/amd64 go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hrbc/Library/Caches/go-build"
GOENV="/Users/hrbc/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hrbc/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7n/bh7jk7s95_3gljs6gf3405k00000gn/T/go-build782113827=/tmp/go-build -gno-record-gcc-switches -fno-common"

like image 334
carousel Avatar asked Mar 20 '20 09:03

carousel


2 Answers

You might try:

sudo chmod -R 777 /usr/local/go

Seems that the go does not have permissions enough to execute some operations. I had the same issue and that fixed for me

like image 64
lucianokrebs Avatar answered Sep 18 '22 15:09

lucianokrebs


Similar issue. For my case, I need to change the owner from root to my user group as well.

ll /usr/local/go                               
total 360
-rwxrwxrwx    1 root  wheel    54K Jun  1 12:44 AUTHORS
-rwxrwxrwx    1 root  wheel   1.3K Jun  1 12:44 CONTRIBUTING.md
-rwxrwxrwx    1 root  wheel    88K Jun  1 12:44 CONTRIBUTORS
-rwxrwxrwx    1 root  wheel   1.4K Jun  1 12:44 LICENSE

run following

sudo chown -R <user>:<group> /usr/local/go
like image 22
Izana Avatar answered Sep 17 '22 15:09

Izana