This simple tutorial shows how to install the latest version of Google’s Go programming language in Ubuntu and Debian.
The open source go language is available in the universe repository of Ubuntu and Debian. However, it’s old and will never receive updates. To get the latest version, here’s how to install it via the official tarball.
1. Remove old 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.
Open terminal either from start menu or by pressing Ctrl+Alt+T on keyboard. When it opens, run command to remove golang:
sudo apt remove --autoremove golang
2. Download the Latest Go Language Tarball:
Now download the Linux tarball from its official website:
Select download the “go1.21.linux-amd64.tar.gz
” package for 64-bit modern PC/laptop, or:
- ‘
go1.21.linux-386.tar.gz
‘ for old 32-bit X86 PC - ‘
go1.21.linux-arm64.tar.gz
‘ for arm64 devices,e.g., Apple Silicon and Raspberry Pi. - or ‘
go1.21.linux-armv6l.tar.gz
‘ for armv6l.
Don’t know the OS architecture? Try uname -m command in terminal.
3. Install Go Language:
After downloaded the source tarball, open terminal by searching from the overview screen (or start menu) and run the commands below one by one.
Then run the commands below one by one to remove old package if any, and extract the tarball to ‘/usr/local’ directory.
- 1.) Firstly, run command to remove old installation if any:
sudo rm -rf /usr/local/go
- 2.) Next, install Go by extracting the tarball to “/usr/local” directory:
sudo tar -C /usr/local -xzf ~/Downloads/go*.linux-amd64.tar.gz
Depends on which package you downloaded, you may replace amd64
in the code with 386, arm64, or armv6l accordingly.
4. Set PATH Environment:
After step 3, you may start using Go by running command:
/usr/local/go/bin/go <command> [arguments]
Instead of typing /usr/local/go/bin/go
every time, you may add it into your PATH.
To do so, run command to edit your ‘profile’ file:
gedit ~/.profile
For Ubuntu 23.04 and higher, replace gedit
with gnome-text-editor
. Or, use nano
command line text editor that works in most Linux.
Finally, save file (for nano, press ‘Ctrl+X’, type ‘y’ and hit Enter). Log out and back in to apply it.
5. Verify:
To verify Go package version, run command in terminal:
go version
It should output something look like:
merilyn@focal:~$ go version
go version go1.21 linux/amd64
(Optional) Remove Go Language
As mentioned in Step 3, you may remove the Go language environment simply by running command in terminal:
sudo rm -rf /usr/local/go
That’s all. Enjoy!
Recent Comments