Skip to content
How to install Go (golang) on Raspberry Pi 3
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md Update README.md Jun 28, 2019
go1.4.3.linux-armv7.tar.gz added binary tar for installing Go Oct 4, 2016

README.md

How to install Go on Raspberry Pi 3

Test environment

#1 Without Go Version Manager (gvm)

Start with go1.4.3

The general idea is that you first download the source and then compile it. But, for your convenience and to bypass this procedure, this git repository has already a binary tar, named go1.4.3.linux-armv7.tar.gz.

rm -rf /usr/local/go
git clone https://github.com/tgogos/rpi_golang.git # (current repository)
cd rpi_golang/
tar -xzf go1.4.3.linux-armv7.tar.gz -C /usr/local
export PATH=/usr/local/go/bin:$PATH
echo "export PATH=/usr/local/go/bin:$PATH" >> /root/.bashrc
go version #test it works

Continue with a newer version (optional)

rm -fr $HOME/go1.4
mkdir -p $HOME/go1.4
tar -xzf go1.4.3.linux-armv7.tar.gz -C $HOME/go1.4 --strip-components=1

rm -fr /usr/local/go
wget https://dl.google.com/go/go1.10.3.src.tar.gz
tar -xz -C /usr/local -f go1.10.3.src.tar.gz

cd /usr/local/go/src
time GOROOT_BOOTSTRAP=/root/go1.4 ./make.bash  # See sample output below
go version  # test that the new version is printed out

Output of ./make.bash

root@rpi:/usr/local/go/src# time GOROOT_BOOTSTRAP=/root/go1.4 ./make.bash
Building Go cmd/dist using /root/go1.4.
Building Go toolchain1 using /root/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.


Building packages and commands for linux/arm.
---
Installed Go for linux/arm in /usr/local/go
Installed commands in /usr/local/go/bin

real    8m42.421s
user    18m36.579s
sys     0m44.624s



root@rpi:/usr/local/go/src# go version
go version go1.10.3 linux/arm

go1.4.3.linux-armv7.tar.gz - how it was created

The following information comes from this source: http://blog.hypriot.com/post/how-to-compile-go-on-arm/

Step-1 Downloaded and compiled the source code

wget https://storage.googleapis.com/golang/go1.4.3.src.tar.gz
rm -rf /usr/local/go
tar -xz -C /usr/local -f go1.4.3.src.tar.gz
cd /usr/local/go/src
time ./make.bash

Step-2 Created the binary tar for further use

tar -czf ~/go1.4.3.linux-armv7.tar.gz -C /usr/local go
tar --numeric-owner -czf ~/go1.4.3.linux-armv7.tar.gz -C /usr/local go

#2 With Go Version Manager (gvm)

https://github.com/moovweb/gvm

sudo apt-get install curl git make binutils bison gcc build-essential
# install gvm
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source /home/pi/.gvm/scripts/gvm

# install go
gvm install go1.4 
gvm use go1.4 
export GOROOT_BOOTSTRAP=$GOROOT 
gvm install go1.7
gvm use go1.7 --default

Configuration of $PATH, $GOPATH variables

From the "Getting Started" page of golang.org:

Add /usr/local/go/bin to the PATH environment variable. You can do this by adding this line to your /etc/profile (for a system-wide installation) or $HOME/.profile:

export PATH=$PATH:/usr/local/go/bin

Most of the times that I have used a combination of Go and Beego framework, I add the following lines:

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go

# and for the `bee` tool:
export PATH=$PATH:$GOPATH/bin
You can’t perform that action at this time.