Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go install always attempts to use GOROOT and GOPATH is not listed under go env

Tags:

go

I'm having a quite frustrating problem with the GOPATH, which, despite being set in .profile, is not appearing when invoking go env, and does not appear to be affecting the go install target location.

I'm attempting to use go install to install packages, and am getting this error, which clearly shows that it is attempting to install in /usr/lib/go, rather than the intended directory of /home/me/dev/go.

$ go install github.com/songgao/colorgo
go install github.com/songgao/go.pipeline: mkdir /usr/lib/go/pkg/linux_386/github.com: permission denied

go env gives the following results.

$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"

But it most certainly is set.

$ echo $GOPATH
/home/me/dev/go

Update: I have exported GOPATH in ~/.profile and sourced it, but I'm still having the same problem.

$ export GOPATH=/home/me/dev/go
$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"

Update again: This problem has ceased since I upgraded to go1.1beta2. I'm not sure what was wrong, because GOPATH appeared to be set correctly, but it's all apparently working now.

like image 858
Alexander Bauer Avatar asked Apr 06 '13 04:04

Alexander Bauer


People also ask

How do I set Gopath and Goroot?

GOROOT and GOPATH are environment variables that define this layout. GOROOT is a variable that defines where your Go SDK is located. You do not need to change this variable, unless you plan to use different Go versions. GOPATH is a variable that defines the root of your workspace.

What is go ENV Gopath?

The command go env GOPATH prints the effective current GOPATH ; it prints the default location if the environment variable is unset. For convenience, add the workspace's bin subdirectory to your PATH : $ export PATH=$PATH:$(go env GOPATH)/bin.


2 Answers

GOPATH and workspaces

$ mkdir -p $HOME/dev/go/src
$ mkdir -p $HOME/dev/go/bin

In $HOME/.profile:

export GOPATH=$HOME/dev/go:
export PATH=$PATH:$HOME/dev/go/bin

Then reboot or log out and log in.

As soon as you have logged in, before anything else, run:

$ env | grep -i '^GO'
GOPATH=/home/me/dev/go
$ cat $HOME/.profile

What output do you get?

like image 60
peterSO Avatar answered Oct 28 '22 06:10

peterSO


Create a soft link, then copy the go binary in /usr/local as follow:

# ln -sf /usr/local/go/bin/go /usr/bin/go
like image 35
GKV Avatar answered Oct 28 '22 06:10

GKV