This is a short post to describe my recommended method for building Go on the Raspberry Pi. This method has been tested on the Raspberry Pi 2 Model B (900Mhz, 1Gb ram) and the older Raspberry Pi 1 Model B+ (700Mhz, 512Mb ram).
This method will build Go 1.5 into you home directory,
As always, please don’t set
$GOROOT. You never need to set
$GOROOT when building from source.
Step 1. Getting the bootstrap Go 1.4 compiler
Go 1.5 requires an existing Go 1.4 (or later) compiler to build Go 1.5. If you have built Go from source on your host machine you can generate this tarball directly, but to save time I’ve done it for you.
% mkdir /usr/local/go % cd /usr/local/go % curl http://www.strongd.net/dl/go/go-linux-arm-bootstrap-c788a8e.tbz | tar xj
Step 2. Fetch the Go 1.5 source
Fetch the Go 1.5 source tarball and unpack it to
% cd /usr/local/go % curl https://storage.googleapis.com/golang/go1.5.src.tar.gz | tar xz
Step 3. Configure your environment and build
Go 1.5 builds cleanly on arm devices, this is verified by the build dashboard, however if you want to see
./all.bash pass on the Raspberry Pi, some additional configuration is recommended.
Lower the default stack size from 8mb to 1mb.
This is necessary because the
runtime tests create many native operating system threads which at 8mb per thread can exhaust the 32bit user mode address space (especially if you are running a recent Raspbian kernel). See issue 11959 for the details.
% ulimit -s 1024 # set the thread stack limit to 1mb % ulimit -s # check that it worked 1024
Increase the scaling factor to avoid test timeouts.
The default scaling factor is good for powerful amd64 machines, but is too aggressive for small 32 bit machines. This is done with the
GO_TEST_TIMEOUT_SCALE environment variable.
Step 4. Build
% cd /usr/local/go/src % env GO_TEST_TIMEOUT_SCALE=10 GOROOT_BOOTSTRAP=/usr/local/go/go-linux-arm-bootstrap ./all.bash # Building C bootstrap tool. cmd/dist # Building compilers and Go bootstrap tool for host, linux/arm. lib9 libbio liblink ... ##### ../test ##### API check Go version is "go1.5", ignoring -next /home/pi/go/api/next.txt ALL TESTS PASSED --- Installed Go for linux/arm in /usr/local/go Installed commands in /usr/local/go/bin
On the Raspberry Pi 2 Model B, this should take around an hour, for the older Raspberry Pi 1 Model B+, it takes more than five!
As a final step you should add
/usr/local/go to your
$PATH, and to save disk space you can remove