I am trying to setup a go dev environment on Ubuntu, and having no luck. Following directions here https://github.com/golang/go/wiki/Ubuntu
sudo apt-get install golang
Then I
mkdir $HOME/golang
export GOPATH=$HOME/golang
No dice. Even doing something simple like go version
throws the following error:
go: cannot find GOROOT directory: /usr/local/opt/go/libexec
Everywhere I look online says simply not to set GOROOT
. Please help, I don't understand where to go from here. This is a fresh install on a fresh VM.
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/isaac/golang"
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/linux_amd64"
TERM="dumb"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CXX="g++"
CGO_ENABLED="1"
This is the install path of the binary file you created with go build . This means that the directory where this binary is installed is /home/ sammy /go/bin/ .
On my ubuntu machine i installed go by following those simple steps:
$ wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xzf go1.4.2.linux-amd64.tar.gz
$ rm go1.4.2.linux-amd64.tar.gz
Add go to your $PATH variable
$ mkdir $HOME/go
$ nano ~/.bashrc
export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
$ source ~/.bashrc
This Works just fine.
So I eventually figured this out, and boy was it dumb on my part. I had a script that was effecting $GOROOT
, and learned alot. Here are the big lessons:
sudo apt-get install golang
it is out of date and doing so means you now have to revert the install. sudo apt-get install golang-go
is also out of date. Just don't use apt-get
.sudo apt-get purge golang
does not reset environment variables or delete all go related folders.unset GOPATH GOHOME GOROOT
is important cleanup before trying another install
ONLY install via tar.gz
from the golang website
tar.gz
lives on your system. Typically /usr/local/go
unset
mkdir
to create that folder as well as set the GOPATH environment variable.$GOROOT/bin:$GOPATH/bin
for the setup to function.Usage of custom scripts that effect .zshrc
or bashrc
or profile
should not contain setting of $GOROOT
!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With