Installing Latest Go Programming Language on Linux

How to install latest Go version manually on Linux

When I was still using Raspberry Pi a few years back, I needed to use Go to compile one of my projects. Sadly, the project required the latest Go version. But the Raspberry Pi OS (used to be called Raspbian back then) package manager didn’t provide the latest version of the Go programming language.

Luckily, it is very easy to install the latest version of Go on Linux manually.

Installing Latest Go Version Manually

First, let’s decide which version of Go you need. By the time I wrote this post, these are what are available to download for Linux:

  • go1.27.1.linux-amd64
  • go1.27.1.linux-arm64
  • go1.27.1.linux-armv6l
  • go1.27.1.linux-386

Since I was using a Raspberry Pi 3 with 32-bit Raspberry Pi OS, what I needed was go1.27.1.linux-armv6l.

So let’s set the variable of $GO_INSTALL_VERSION.

GO_INSTALL_VERSION="go1.27.1.linux-armv6l"

Once it’s done, let’s download the binary first. I’d be using wget for this.

$ wget "https://dl.google.com/go/$GO_INSTALL_VERSION.tar.gz"

Before we extract the Go package, we need to remove the existing go installation if any. You can do it by removing the following directory (may require sudo).

rm -rf /usr/local/go

Next, we can start a fresh installation of Go. Let’s extract the downloaded Go tar archive into the /usr/local directory.

$ sudo tar -C /usr/local -xzf $GO_INSTALL_VERSION.tar.gz

Once it’s done, the go directory will be available at /usr/local/go.

Now we need to add this new directory into the $PATH environment variable. We also need to set the $GOPATH environment variable.

You can set it per user by editing the ~/.profile file.

$ vim $HOME/.profile

Or you can set it for all users (system-wide installation) by editing /etc/profile.

$ sudo -E vim /etc/profile

Enter the following lines at the end of the file.

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$(go env GOPATH)
export PATH=$PATH:$(go env GOPATH)/bin

Save the profile changes and start a new terminal session. This time you can use the go binary.

You can verify it using the following command:

go version

Final Thoughts

That’s it for today’s post. Thanks for reading and see you around!

References