Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$GOPATH must not be set to $GOROOT, why not?

Tags:

go

I've installed Go on my Linux machine in /usr/local/go, and intended to use /usr/local/go/src for development. However when I try this I get the following error:

$GOPATH must not be set to $GOROOT 

Effectively as I understand it, this means you shouldn't use /usr/local/go for development. Why not?

like image 846
Kevin Burke Avatar asked Apr 05 '14 07:04

Kevin Burke


People also ask

Do you need to set Gopath?

The GOPATH environment variableIf you would like to work in a different location, you will need to set GOPATH to the path to that directory.

What should Goroot and Gopath be set to?

You generally should not set GOROOT explicitly. The go command identifies the appropriate GOROOT automatically based on its own directory location. GOPATH defaults to $HOME/go . You only need to set it explicitly if you want to put it somewhere else.

Can Gopath and Goroot be the same?

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 the default Gopath?

Default GOPATH is: $HOME/go on Unix-like systems. %USERPROFILE%\go on Windows.


2 Answers

Because /usr/local/go/src already contains the code for the standard library, and you should keep your own code separate from that.

I know, other development tools would have no problem with that, but Go is a little more strict in some ways. It's probably the same philosophy that lies behind flagging unused variables or imports as errors - avoiding problems which may seem small at first, but can lead to bigger headaches in the future.

like image 135
rob74 Avatar answered Oct 02 '22 01:10

rob74


Add following lines to your .bashrc file:

export GOPATH="${HOME}/workspace" export GOROOT="${HOME}/go" export PATH="${GOPATH}/bin:${PATH"} 

Then load the bashrc: $ source .bashrc

like image 44
Yrineu Rodrigues Avatar answered Oct 02 '22 01:10

Yrineu Rodrigues