Monday, November 23, 2015

Building Go 1.5 from source

I was trying to build Go v1.5 from source and ran it to the following error.

$ git clone
$ git checkout -b v1.5.1 go1.5.1
$ cd src
$ ./all.bash
##### Building Go bootstrap tool.
ERROR: Cannot find /home/arun/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
./make.bash: line 121: /home/arun/go1.4/bin/go: No such file or directory

After some googling [1] [2], it turns out starting with version 1.5 Go requires Go to build itself.

Bootstrapping Go 1.4

We cannot use Go 1.5 to bootstrap itself. So, first build Go 1.4 which will be used to build Go 1.5.

$ mkdir build
$ cd build
$ git clone go-1.4
$ cd go-1.4
$ git checkout -b v1.4.3 go1.4.3
$ cd src
$ ./make.bash

Building Go 1.5

Use Go 1.4 we built in the earlier step to build Go 1.5.

$ cd ~/go/src
$ GOROOT_BOOTSTRAP=~/build/go-1.4 ./make.bash

Go v1.5 is now installed in ${HOME}/go.

$ go version
go version go1.5.1 linux/amd64

Test Installation

Add the location of go binaries (${HOME}/go/bin) to the PATH. I have the following in ${HOME}/.bash_profile file.

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

Write a customary "helloworld" program and run it to ensure that the Go build is working.

$ go run helloworld.go
Hello, world!


When building Go from source, we can run ./all.bash instead of ./make.bash to build and run all the unit tests. Only downside is it increases the build time.