Raspberry Pi-4 Model-B

If you want to install Go on your Raspberry Pi you have a few options. In the past, there was a lot of cross-compiling and hacking to get it done, but now you can install it through Apt. However, you’re likely to find an older version.

For instance, at the time of this writing, an updated Raspberry Pi OS shows a version of 1.15.1 in the repositories. However, the current version is 1.18.1. So if the latest version is important to you, here’s your solution.

Step 0: Remove the Old Installed Golang Package

For those who have already installed the old version via the apt command, backup your projects and remove the old installation via the command below.

sudo apt remove --autoremove golang

Step 1: Get the Latest Package

To get the latest version, browse on over to the Go download page and look for the latest version.

Pick the version that is right for your Raspberry Pi. For example, Raspberry PI 4 can run 64-bit OS, so you want to get the arm64 version here. For older Raspberries or 32-bit OS, you should pick the armv6 version.

Whichever archive you choose, use wget to download it:

wget https://go.dev/dl/go1.18.1.linux-arm64.tar.gz

Step 2: Extract the Package and Install Golang

After downloading the tarball, it is time to install the new version of Golang. We will install it into the /usr/local/ directory.

First, run the following command, to make sure there are no files from an older attempt/installation left.

sudo rm -rf /usr/local/go

Now, install Golang by extracting the downloaded tarball. To do so, run:

sudo tar -C /usr/local -xvf go1.18.1.linux-arm64.tar.gz

When successful you should see the following:

Step 3: Set the PATH Environment

This is only needed when you’re doing this the first time, but it can’t hurt to check anyway.

nano ~/.profile

And add the following at the end of the file:

# For Golang

Notice here you can set your go path to whatever you like. I prefer /go but you can put this wherever you want.

Update your shell with your changes:

source ~/.profile

And check your version with:

go version

(Optional) Remove Golang

As mentioned in Step 2, you may remove Golang simply by running this command:

sudo rm -rf /usr/local/go/

Leave a Reply

Your email address will not be published. Required fields are marked *