I wanted to install Go on Ubuntu 16.04. I thought this would be easy. It kinda is, but it wasn’t super easy.
By easy I mean I found a bunch of copy / paste instructions, but not everything worked first time.
Here’s what I had to do:
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
This prompted me to run a further command:
When I tried to run:
I was prompted to install bison:
sudo apt-get install bison
I then ran:
Which showed go1.9.2 as being the latest and greatest.
gvm install go1.9.2
Unfortunately that failed.
The instructions I found gave a suggested fix, but this didn’t work. Here’s what did work for me:
gvm install go1.4 --binary gvm use go1.4 export GOROOT_BOOTSTRAP=$GOROOT gvm install go1.9.2 gvm use go1.9.2
go version go version go1.9.2 linux/amd64
For what it’s worth:
go env GOARCH="amd64" GOBIN="/home/chris/go/bin" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/chris/go" GORACE="" GOROOT="/home/chris/.gvm/gos/go1.9.2" GOTOOLDIR="/home/chris/.gvm/gos/go1.9.2/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build165142315=/tmp/go-build -gno-record-gcc-switches" CXX="g++" CGO_ENABLED="1" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config"
I also hit on a bunch of confusing issues because I’d set my package name to be something different to main .
I’d set my package name to cfbl which resulted in this like this:
cfbl go build cfbl go install go install: no install location for directory /home/chris/Development/go/cfbl outside GOPATH For more details see: 'go help gopath' cfbl go run test.go go run: cannot run non-main package
Inside test.go (which isn’t a TDD style test, just my testing with go) I had to make sure to use package main
I hope that saves someone some confusion.