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

Permission denied while running go install #40417

Closed
Jbiloki opened this issue Jul 26, 2020 · 4 comments
Closed

Permission denied while running go install #40417

Jbiloki opened this issue Jul 26, 2020 · 4 comments

Comments

@Jbiloki
Copy link

@Jbiloki Jbiloki commented Jul 26, 2020

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

Go version: go1.14.6 darwin/amd64

@ALTree
Copy link
Member

@ALTree ALTree commented Jul 26, 2020

When running go install on my cmd folder [...]

You didn't write the exact command you're running, but if you're running go install cmd then be aware that it doesn't do what you want. go install cmd will try to (re)install the Go toolchain commands (go, gofmt); since these are usually in /usr/local/go, if you try that without being su the install command will fail with permission errors.

What you want is go install ./cmd or similar.

@Jbiloki
Copy link
Author

@Jbiloki Jbiloki commented Jul 26, 2020

I see, yeah that does seem to be the issue I changed my structure and have a shell script runs cd project_name go install . that seems to do the trick. Is a shell script the correct way to orchestrate building/running a go binary or should I use a Makefile?

@ALTree
Copy link
Member

@ALTree ALTree commented Jul 27, 2020

Is a shell script the correct way to orchestrate building/running a go binary

In general, unless the project is really big and the build steps complicated, you just directly run the go commands in the command line (or this is at least what I like to do). If you have many steps, a makefile can be used, too.

Please note that the Go project does not use its bug tracker for general discussion or asking questions about the language. See the Questions wiki page if you have further questions.

I'm now closing this issue, since we don't have a Go bug.

@ALTree ALTree closed this Jul 27, 2020
@Jbiloki
Copy link
Author

@Jbiloki Jbiloki commented Jul 27, 2020

Thanks for clarifying and for your help!

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
2 participants
You can’t perform that action at this time.