Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be the values of GOPATH and GOROOT?

Tags:

go

gopath

I'm trying to install doozer like this:

$ goinstall github.com/ha/doozer 

I get these errors.

goinstall: os: go/build: package could not be found locally goinstall: fmt: go/build: package could not be found locally goinstall: io: go/build: package could not be found locally goinstall: reflect: go/build: package could not be found locally goinstall: math: go/build: package could not be found locally goinstall: rand: go/build: package could not be found locally goinstall: url: go/build: package could not be found locally goinstall: net: go/build: package could not be found locally goinstall: sync: go/build: package could not be found locally goinstall: runtime: go/build: package could not be found locally goinstall: strings: go/build: package could not be found locally goinstall: sort: go/build: package could not be found locally goinstall: strconv: go/build: package could not be found locally goinstall: bytes: go/build: package could not be found locally goinstall: log: go/build: package could not be found locally goinstall: encoding/binary: go/build: package could not be found locally 
like image 442
jshen Avatar asked Nov 01 '11 17:11

jshen


People also ask

Should Goroot and Gopath 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 should be Gopath in Windows?

GOPATH is an environment variable that is used to specify the root of your Go workspace. By default, the workspace located at %USERPROFILE%/go for Windows. To configure GOPATH follow the steps mentioned below: Create a new folder in your C drive called "C:\Projects\Go".

Where should Gopath be set?

The GOPATH environment variable specifies the location of your workspace. It defaults to a directory named go inside your home directory, so $HOME/go on Unix, $home/go on Plan 9, and %USERPROFILE%\go (usually C:\Users\YourName\go ) on Windows.

What is the default Gopath?

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


1 Answers

GOPATH is discussed in the cmd/go documentation:

The GOPATH environment variable lists places to look for Go code. On Unix, the value is a colon-separated string. On Windows, the value is a semicolon-separated string. On Plan 9, the value is a list.

GOPATH must be set to get, build and install packages outside the standard Go tree.

GOROOT is discussed in the installation instructions:

The Go binary distributions assume they will be installed in /usr/local/go (or c:\Go under Windows), but it is possible to install the Go tools to a different location. In this case you must set the GOROOT environment variable to point to the directory in which it was installed.

For example, if you installed Go to your home directory you should add the following commands to $HOME/.profile:

export GOROOT=$HOME/go export PATH=$PATH:$GOROOT/bin 

Note: GOROOT must be set only when installing to a custom location.

(updated version of Chris Bunch's answer.)

like image 52
pje Avatar answered Oct 17 '22 06:10

pje