Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go build -i results in "/usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied" #37962

Open
xiaoxfan opened this issue Mar 20, 2020 · 6 comments
Milestone

Comments

@xiaoxfan
Copy link

@xiaoxfan xiaoxfan commented Mar 20, 2020

What version of Go are you using (go version)?

$ go version
go version go1.14 darwin/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ 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"

What did you do?

build my project use -i
go build -i -v -o ./bin/demo-api .

What did you expect to see?

no error

What did you see instead?

go build -i -v -o ./bin/demo-api .
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

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Mar 20, 2020

This probably means that your go installation is read-only and/or owned by root instead of your user.

The -i flag is not particularly useful now that the go command has a build cache. Is there some particular reason you need it?

@bcmills bcmills changed the title go1.14 go build -i cause /usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied cmd/go: go build -i results in "/usr/local/go/pkg/darwin_amd64/runtime/cgo.a: permission denied" Mar 20, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Mar 20, 2020
@ppinter1

This comment has been minimized.

Copy link

@ppinter1 ppinter1 commented Mar 22, 2020

I had the same error when I installed golang using the .pkg file. Oddly(?), it only offered to install system-wide (i.e. for all users) and all the files installed to /usr/local/go were owned by root.

Removing golang (sudo rm -fr /usr/local/go), downloading and expanding the latest tar file helped:

sudo tar -C /usr/local -xzf go1.14.1.darwin-amd64.tar.gz

I no longer have that fakakta error. If it matters, I'm on macOS Mojave 10.14.6.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Mar 23, 2020

To clarify, the -i flag tells the go command to install any rebuilt packages to their canonical locations. For runtime/cgo, that would be $GOROOT/pkg/darwin_amd64/runtime/cgo.a, which may be read-only, depending on how Go was installed.

Since Go 1.10, which introduced the build cache, the -i flag should rarely be needed. runtime/cgo.a will be stored there with a name like ~/Library/Caches/go-build/63/63a132c80210b5c7b4f4ed9a902aaec712c42b15e23aa2c1b1778e2f85165d04-d.

@xiaoxfan @ppinter1 Could you say more about what you're using -i for? If the intent is just to speed up future builds by caching compiled packages, it's no longer needed.

@ppinter1

This comment has been minimized.

Copy link

@ppinter1 ppinter1 commented Mar 23, 2020

In my case, I sometimes use the CLI, but mostly build projects using VScode with go extensions.

The VScode setting go.installDependenciesWhenBuilding defaults to true and adds the -i switch on building, but I believe that's a red herring and the underlying problem is that the go1.14.1.darwin-amd64.pkg file is hosed. If used, go gets installed with 'root' ownership.

However, using sudo to expand the go1.14.1.darwin-amd64.tar.gz file to /usr/local works.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Mar 23, 2020

@ppinter1 Thanks for clarifying. I remember changing the default was discussed in microsoft/vscode-go#2836. Maybe comment on that issue or open a new one?

It's expected that go1.14.1.darwin-amd64.pkg installs Go with root ownership. Any system-wide package installation should work that way. Personally, I use the .tar.gz files, but I have a script that chowns them to root so I don't accidentally mess up my installation later (I have in the past).

@ppinter1

This comment has been minimized.

Copy link

@ppinter1 ppinter1 commented Mar 23, 2020

Ah, okay. Thanks for clearing that up. It's a good day when I learn summit and today's a good day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.