Every time I install Go on to my new machine, I forget to do something that eventually bites me. Setting my GOPATH/GOBIN
variables. If they are not set, whenever you use go get
to install binaries, the commands will not be found.
The easy steps to fix this (which I always forget are):
- Setting the
GOPATH
variable if it’s not set. There are 2 methods.
Runninggo env -w GOPATH=$HOME/go
where$HOME/go
or addingexport GOPATH=$HOME/go
to yourrc
file (in most cases.bashrc
or.zshrc
. - Setting the
GOBIN
variable if it’s not set. There are again 2 methods.
Runninggo env -w GOBIN=$HOME/go/bin
, where$HOME/go/bin
has binaries obtained throughgo get
. You can also add the following lines to yourrc
file,export $GOBIN=$HOME/go/bin
. - Finally just add the
GOBIN
variable to your path by addingexport PATH=$PATH:$GOBIN
to yourrc
file.