Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install Go packages

Tags:

go

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)

like image 866
utkbansal Avatar asked Nov 17 '15 08:11

utkbansal


People also ask

How to install a package with Go Get?

- 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.

How do I update a package in go?

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.

Why do we need to import go packages?

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.

How do I install the flect package in go?

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:


1 Answers

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:

  1. Log in as root (or su, or sudo su, or ...)
  2. Set $GOPATH to your normal user $GOPATH ("/home/utkbansal/go")
  3. Update godoc, using go get -u golang.org/x/tools/cmd/godoc, or all tools
  4. Set the appropriate permissions on for your $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.

like image 58
mrd0ll4r Avatar answered Oct 05 '22 23:10

mrd0ll4r