Install GoLang (Google Language) on Linux

Go Language (Google)

The current stable version available at Golang official website is v1.12.6, and there is a distribution packaged for ArmV6 CPU available that is suitable for Raspberry Pi 3 (and some earlier models). Right click on the link that has armv6l on it to copy the link URL, and type wget on Raspberry Pi terminal and paste the link to download the golang:

wget https://dl.google.com/go/go1.12.6.linux-armv6l.tar.gz

Decompress the downloaded package and move it to /usr/local directory:

sudo tar -C /usr/local -xzf go1.12.6.linux-armv6l.tar.gz
rm go1.12.6.linux-armv6l.tar.gz

Setup path
The following steps are required even you choose to install Golang using “The Easy Way”, and the steps shown are based on Raspberry Pi OS (i.e. Raspbian), for other OS, the commands might varies.
We now need to add the PATH environment variable that are required for the system to recognize where the Golang is installed. To do that, edit the ~/.profile file:

nano ~/.profile

Scroll all the way down to the end of the file and add the following:

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

I’m going to store my Golang projects at the ~/golang directory, if you like to store it somewhere else or want to have the directory named go instead of golang, feel free to change the GOPATH=$HOME/golang to something else. Finally we need to make the system aware of the new profile.

source ~/.profile

Type which go to find out where the Golang installed and go version to see the installed version and platform.

hcheung@e-tinkers:~ $ which go
/usr/local/go/bin/go
hcheung@e-tinkers:~ $ go version
go version go1.12.6 linux/arm

Golang organizes its code files based on a pre-defined code organization structure. So let’s create the project directories:

mkdir golang
mkdir golang/src