When I run go get
, I get a permission Denied error and when I try sudo go get
I get a GOPATH not set error.
utkbansal@Dell:~$ go get -u golang.org/x/tools/cmd/...
go install golang.org/x/tools/cmd/godoc: open /usr/lib/go/bin/godoc: permission denied
utkbansal@Dell:~$ sudo go get -u golang.org/x/tools/cmd/...
package golang.org/x/tools/cmd/...: cannot download, $GOPATH not set. For more details see: go help gopath
Here are the result of my $PATH, go env and which go commands.
utkbansal@Dell:~$ which go
/usr/lib/go/bin/go
utkbansal@Dell:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/utkbansal/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
utkbansal@Dell:~$ $PATH
bash: /usr/lib/go/bin:/home/utkbansal/miniconda/bin:/usr/local/heroku/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin: No such file or directory
How do I fix this?
I am using go1.5 from this PPA https://launchpad.net/~ubuntu-lxc/+archive/ubuntu/lxd-stable (ppa:ubuntu-lxc/lxd-stable)
- GeeksforGeeks How to Install a package with GO get? In the Go language, we can use the go get command to download and install the packages and dependencies. Various repositories have the support to go get like Azure Repos Git and GitHub Repos.
To update a package, you can use the -u flag with the go get command: This command will also have Go install the package if it is not found locally. If it is already installed, Go will attempt to update the package to the latest version.
When we import packages we’re able to call functions that are not built in to Go. Some packages are part of the standard library that installs with Go, and some we will install through go get. Making use of packages allows us to make our programs more robust and powerful as we’re leveraging existing code.
That path can also be a path to a public project that is hosted in a code repository such as GitHub. As such, if you want to import the flect package, you would use the full canonical path: The go get tool will find the package, on GitHub in this case, and install it into your $GOPATH. For this example the code would be installed in this directory:
godoc
seems to be an exception to the general go get
practice, because it installs to the go installation ($GOROOT/bin
) instead of $GOPATH
. So, if you really need to update godoc
(why?), what you need to do is:
su
, or sudo su
, or ...)$GOPATH
to your normal user $GOPATH
("/home/utkbansal/go"
)godoc
, using go get -u golang.org/x/tools/cmd/godoc
, or all tools$GOPATH
, i.e. chown -R utkbansal:utkbansal $GOPATH
(still as root)That should work I guess. BUT: Why would you want to update godoc
? If you just want one specific tool that is not pre-installed, you should be able to go get
it without root privileges.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With