douju2012 2015-11-17 08:29
浏览 115
已采纳

无法安装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)

  • 写回答

8条回答 默认 最新

  • dqaxw44567 2015-11-17 11:17
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(7条)

报告相同问题?