Closed fracturedpsyche closed 7 years ago
What about setting GOROOT explicitly with GOROOT=/usr/local/go sudo go run ...
or just in your shell or .bashrc with export GOROOT=/usr/local/go
?
That does not work either. Trying to do anything with go as sudo results in the same error. My test is to run "sudo go version" and that returns the same error.
Strange. And when you just compile your GO code first with go build .
And then running the binary with sudo?
That does not work either. I have also tried installing go to the directory that sudo is expecting. When I do that, I can execute go commands, but I cannot build or run anything because sudo does not see GOPATH.
Can you please give a little be more details about your device? Device type, OS, etc. You can also try to compile the latest Go 1.6.3 from source on this device, just following my tutorial at http://blog.hypriot.com/post/how-to-compile-go-on-arm/. Or looking for help at the GOLANG team, they do have now GO tarballs available at least for ARMv6 and then compile GO 1.6.3 from source again.
I am actually going to rebuild the OS on this machine and start fresh. I will report my status after that and if I am still having issues I will post more specifics.
As sudo opens up a new subshell with root privileges:
sudo GOROOT=/usr/local/go go version
should work ;-) (pay attention to the position of sudo)
OK. I have an update. I completely rebuilt the board I am using. I flashed the OS, downloaded the 1.6.2 arm64 build from your releases, extracted to /usr/local/go.
When I try to execute "go version" as any user I get "go: cannot find GOROOT directory: /usr/src/go".
I have not made any changes other than what I typed here. I have never attempted to set GOROOT. I exported the PATH and that is all.
Here is what I am working on:
Qualcomm Dragonboard 410c running the supported version of Linaro Linux.
Please post the output of printenv
and sudo printenv
By the way have you extended your PATH
variable as described https://golang.org/doc/install
@firecyberice your solution from 3 hours ago seems to work for sudo. Kind of a pain but it is what it is. Thank you both for your help!
Some updates to /etc/sudoers should work around this nicely.
Defaults secure_path="$YOUR_GO_BIN_DIR:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults env_keep += "GOPATH"
If anybody is interested, you can automate this with a script (for CI) using the following syntax (note the tee command -- it's important):
echo 'Defaults env_keep += "GOPATH"' | sudo tee --append /etc/sudoers.d/env_keep
Seems to be solved. So I close this issue.
Hello! I am having an issue where I cannot run GO as sudo. I am working on a project using bluetooth low energy (which requires running code with root access) and when I run "sudo go run ..." to execute my bluetooth code I get an error:
go: cannot find GOROOT directory: /usr/src/go
When I extracted the arm64 tarball I put it in /usr/local/go.