What is GOPATH?


(HACHIROU) #1

hi , my go main directory is placed in
/usr/local/go
which contains all golang main files ,
my source files are in
/home/rootx/Documents/sourceCode/go/src
i also added
:/usr/local/go/bin
to
/etc/environment
, now when i type
go env
i get
GOPATH="/home/rootx/go"
, and there is no /go file in this path , so how can i change it ? and what is GOPATH ?

thank you for your support


(Norbert Melzer) #2

The GOPATH is the root of your go workspace.

It defaults to ~/go, but you can set the environment variable GOPATH to override the default.

How to set an environment variable depends on your operating system.

It looks as if you were using linux, so it should usually be enough to have export GOPATH=… in your shells RC file.

You usually do not want to set this system wide, but only for the current user, so /etc/environment is not a good place.


(Lutz Horn) #3

See


(HACHIROU) #4

thanks for the support


(Eric Lindblad) #5

Can I set multiple $GOPATH? (Go Forum / Oct 3, 2019)

wiki: SettingGOPATH (redesign) #34967 (Issues / Oct 19, 2019)