Last updated:

Quick answer: run sudo apt install golang-go to install the Go version that ships with your Ubuntu release (Go 1.26 on Ubuntu 26.04, Go 1.22 on Ubuntu 24.04). If you need the newest Go release, download the Linux archive from go.dev/dl, extract it into /usr/local and add /usr/local/go/bin to your PATH, or install the snap with sudo snap install go --classic. Check the result with go version.

Method Ubuntu 26.04 (resolute) Ubuntu 24.04 (noble) Updates
golang-go (APT) Go 1.26 (golang-defaults 2:1.26~1) Go 1.22.2 (golang-go 2:1.22~2build1) With apt upgrade, same minor version
Versioned package, e.g. golang-1.26-go 1.26.8 in resolute-updates 1.26.8 in noble-updates With apt upgrade
Official tarball from go.dev Go 1.27.4 (current stable on go.dev, checked 11 Nov 2026) Manual: download and extract again
Snap (go --classic) 1.27.4 in latest/stable (Snap Store, 11 Nov 2026) Automatic snap refreshes

Go (often called Golang) is Google’s open-source programming language. You only need one of the methods below. Use APT if the packaged version is new enough for your project, and use the official tarball when a project’s go.mod asks for a newer Go than Ubuntu ships. The package versions above were read from the Ubuntu archive (Launchpad for 26.04, apt-cache policy for 24.04). The APT commands, the test program and the PATH setup were run on Ubuntu 24.04 on 11 Nov 2026. They were not run on a 26.04 machine, but the package names and paths are the same there. The screenshots in this guide come from the original 2024 version of the article on Ubuntu 24.04.

Method 1: Install Go from the Ubuntu repositories (APT)

This is the simplest method and the packages get security updates through the normal Ubuntu update process. First refresh the package lists:

sudo apt update
sudo apt update -y refreshing the package lists on Ubuntu 24.04 (noble)
Refreshing the package lists (Ubuntu 24.04, original 2024 screenshot).

Then install the golang-go package. It is a small package that points /usr/bin/go at the default Go version for your release:

sudo apt install golang-go
sudo apt install golang-go reporting golang-go 2:1.22~2 is already the newest version on Ubuntu 24.04
On Ubuntu 24.04 the golang-go package installs Go 1.22.

Check the version. You do not need sudo for this or for any other go command in this guide:

go version

On Ubuntu 24.04 the output in our test was:

go version go1.22.2 linux/amd64
sudo go version printing go version go1.22.1 linux/amd64
Checking the version (original 2024 screenshot). sudo is not needed for go version.

Need a newer Go on Ubuntu 24.04? Use a versioned package

Ubuntu 24.04 also carries newer Go toolchains as separate packages named golang-1.XX-go (1.23, 1.24, 1.25 and 1.26 were available in noble-updates when this was checked). They install next to the default version under /usr/lib/go-1.XX and do not change /usr/bin/go, so you have to put their bin folder first in your PATH:

sudo apt install golang-1.26-go
echo 'export PATH=/usr/lib/go-1.26/bin:$PATH' >> ~/.profile
source ~/.profile
go version

Before and after changing PATH in our test, the same terminal showed:

$ go version
go version go1.22.2 linux/amd64
$ export PATH=/usr/lib/go-1.26/bin:$PATH
$ go version
go version go1.26.8 linux/amd64
$ which go
/usr/lib/go-1.26/bin/go

Test the installation with a small program

Modern Go projects are modules, so create a folder with a go.mod file first:

mkdir ~/hello && cd ~/hello
go mod init example.com/hello
nano hello.go
Ubuntu Files app showing an extracted go folder with Copy selected in the path bar menu
Original 2024 screenshot from the tarball method: copying the path of a go folder extracted to the Desktop. Extracting to /usr/local/go (Method 2) makes this step unnecessary.

Paste this program and save the file (Ctrl+O, Enter, Ctrl+X). Keep the opening brace on the same line as func main(); Go does not compile it otherwise (see the troubleshooting table below):

package main

import "fmt"

func main() {
	fmt.Println("Hello from Go on Ubuntu")
}
go version printing go1.22.1 linux/amd64 in the Desktop folder
go version output from the original 2024 test.

Run it, then build a standalone binary:

go run .
go build -o hello
./hello

Output from our Ubuntu 24.04 test with Go 1.22.2:

$ go mod init example.com/hello
go: creating new go.mod: module example.com/hello
go: to add module requirements and sums:
	go mod tidy
$ go run .
Hello from Go on Ubuntu
$ go build -o hello && ./hello
Hello from Go on Ubuntu
sudo go run goapp.go printing My first GO app
Running a test program (original 2024 screenshot). Run go run as your normal user, without sudo.
Advertisement

Method 2: Install the latest Go from go.dev with wget (official tarball)

This is the method the Go project documents on go.dev/doc/install. It always gives you the newest release, and it works the same on Ubuntu 26.04 and 24.04. Check go.dev/dl for the current file name; at the time of writing it was go1.27.4.linux-amd64.tar.gz (use linux-arm64 on ARM machines, and uname -m shows which one you have).

cd /tmp
wget https://go.dev/dl/go1.27.4.linux-amd64.tar.gz
wget downloading go1.22.1.linux-amd64.tar.gz from go.dev and following the redirect to dl.google.com
The go.dev/dl link redirects to dl.google.com. Download the current release instead of the 1.22.1 file shown here.

Compare the checksum with the SHA256 value listed next to the file on go.dev/dl. For go1.27.4.linux-amd64.tar.gz it is 7226736c2339719cda28fbf3a54d71aa63bcefe376e98cef00034268dab24840:

sha256sum go1.27.4.linux-amd64.tar.gz

Now remove any earlier tarball install and extract the new one into /usr/local. The Go documentation warns that extracting over an existing /usr/local/go tree produces a broken installation, so always delete the old folder first. This only removes Go itself, not your projects in ~/go or elsewhere:

sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.27.4.linux-amd64.tar.gz
tar -xvzf go.tar.gz extracting the Go archive in the Desktop folder
Original 2024 screenshot: extracting into the Desktop. The official method extracts into /usr/local instead (command above).

The older version of this guide extracted the archive on the Desktop and copied its path into a GOROOT variable, as the next screenshots show. That still runs, but it is not needed: when Go lives in /usr/local/go it finds its own files, and you only have to add it to PATH. If you want to see what is inside the tree, our guide to extracting tar.gz files explains how to list an archive before unpacking it.

Ubuntu desktop right-click menu with Open selected on the extracted go folder
Original 2024 screenshot: opening the extracted folder (only needed for the old Desktop layout).
Files app path bar showing /home/ubuntuuser/Desktop/go with Copy highlighted
Original 2024 screenshot: copying the folder path for GOROOT (not needed with /usr/local/go).

Open ~/.profile:

nano ~/.profile
nano ~/.profile command in the Ubuntu terminal
Opening ~/.profile to add Go to PATH.

Add these two lines at the end of the file. The first makes the go command available, the second makes programs you install with go install (they land in ~/go/bin) available too:

export PATH=/usr/local/go/bin:$PATH
export PATH="$PATH:$HOME/go/bin"
~/.profile in nano with export GOROOT, GOPATH and PATH lines for a Go folder on the Desktop
The old 2024 lines set GOROOT to a Desktop folder. With Go in /usr/local/go, only the PATH lines shown above are needed.

Why /usr/local/go/bin goes first: go.dev appends it to the end of PATH. That is fine on a clean system, but if golang-go from APT is also installed, the older /usr/bin/go wins. In our test with both installed, appending gave /usr/bin/go (go1.22.2), while putting /usr/local/go/bin first gave the tarball version. Either remove the APT package or put the tarball first, as above.

Load the new settings in the current terminal (new terminals and logins read ~/.profile automatically):

Stuck at this step? Ask us, it is free and include the exact error.

source ~/.profile
source ~/.profile reloading the profile in the current terminal
Reloading ~/.profile in the current terminal.

Confirm which go runs and its version:

type -a go
go version

With both an APT Go and a Go tree in /usr/local/go (Go 1.24.7 on our test system), the output after the profile change was:

go is /usr/local/go/bin/go
go is /usr/bin/go
go is /bin/go
go version go1.24.7 linux/amd64
go version printing go1.22.1 linux/amd64 after the tarball install
Verifying the tarball install (original 2024 screenshot, Go 1.22.1).

To upgrade later, download the newer archive and repeat the rm and tar commands; your PATH lines stay the same.

Method 3: Install Go with Snap

Canonical publishes Go as a classic snap, which refreshes automatically. Classic confinement means the snap can read and write files anywhere like a normal program, which a compiler needs:

sudo snap install go --classic
sudo snap install go --classic installing go 1.22.1 from Canonical
Installing the Go snap (2024 screenshot; the latest/stable channel now carries a newer release).

To stay on one minor version instead of following the newest release, pick a channel, for example sudo snap install go --channel=1.26/stable --classic. snap info go lists the channels. Then check the version (the snap install was not re-run for this update; the Snap Store listed 1.27.4 in latest/stable on 11 Nov 2026):

go version
sudo go version printing go1.22.1 linux/amd64 after the snap install
Checking the snap version (original 2024 screenshot).

If go version still shows an older version after installing the snap, another Go is earlier in your PATH; type -a go lists every copy (the snap one is in /snap/bin). Test it the same way as in Method 1:

nano gosample.go
nano gosample.go command in the terminal
Creating a test file.
package main

import "fmt"

func main() {
	fmt.Println("Installing Go using the snap")
}
gosample.go in nano with package main, import fmt and a main function that prints Installing GO using the Snap
Test program. The opening brace must be on the same line as func main().
go run gosample.go
sudo go run gosample.go printing Installing GO using the Snap
Test program output (original 2024 screenshot).

Method 4: Download the tarball with curl instead of wget

If you prefer curl, only the download step changes. Install curl if it is missing:

sudo apt install curl
sudo apt install curl installing the curl package on Ubuntu 24.04
Installing curl.

Then download with -L (follow the go.dev redirect to dl.google.com) and -O (keep the file name), and continue with the checksum, rm, tar and PATH steps from Method 2:

cd /tmp
curl -LO https://go.dev/dl/go1.27.4.linux-amd64.tar.gz
sha256sum go1.27.4.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.27.4.linux-amd64.tar.gz

If you add the PATH line with echo instead of an editor, use single quotes so that $PATH is written literally and expanded each time you log in:

echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.profile
echo 'export PATH="$PATH:$HOME/go/bin"' >> ~/.profile
source ~/.profile
echo command appending an export PATH line with /usr/local/go/bin and $GOPATH/bin to ~/.profile
Original 2024 screenshot. With double quotes, $PATH is expanded when echo runs, so the whole current PATH is copied into ~/.profile. Use the single-quoted commands above instead.
Files app showing the contents of an extracted go folder (api, bin, doc, lib, misc, pkg, VERSION) with Copy selected
Contents of an extracted Go tree (original 2024 screenshot).

Run a test program and check the version:

go run gosample.go printing Installing GO using the Snap
Running a test program (original 2024 screenshot reused from the snap test).
go version
go version printing go1.22.1 linux/amd64 after the curl install
Verifying the curl install (original 2024 screenshot).
Advertisement

Troubleshooting

Symptom Cause Fix
go: command not found /usr/local/go/bin is not in PATH, or the profile was not reloaded Check the lines in ~/.profile, run source ~/.profile or log out and back in
go version shows an older version than you installed Another Go (often /usr/bin/go from APT) comes first in PATH Run type -a go; remove the other copy or put the one you want first in PATH
syntax error: unexpected semicolon or newline before { The opening brace of a function is on its own line. Go inserts a semicolon at the end of the func main() line Write func main() { on one line, or run gofmt -w file.go
go: go.mod requires go >= 1.XX The project needs a newer Go than the APT version Install a versioned package (Ubuntu 24.04) or the go.dev tarball
sudo go ... says command not found but go works sudo uses its own secure PATH without /usr/local/go/bin Do not use sudo for go commands; build as your user
Strange errors right after an upgrade A new tarball was extracted over the old /usr/local/go Delete /usr/local/go and extract the archive again

This is the exact error we got on Ubuntu 24.04 when the brace was placed on its own line, as in the older version of this guide:

$ go run broken.go
# command-line-arguments
./broken.go:4:1: syntax error: unexpected semicolon or newline before {

Remove Go from Ubuntu

Installed with Remove with
APT (golang-go) sudo apt remove golang-go && sudo apt autoremove
Versioned APT package sudo apt remove golang-1.26-go, then delete its line from ~/.profile
Snap sudo snap remove go
Tarball (wget or curl) sudo rm -rf /usr/local/go, then delete the PATH lines from ~/.profile

Removing Go does not delete ~/go, which holds downloaded modules and programs installed with go install. Delete it yourself only if you no longer need them. Afterwards, type -a go should print nothing.

Which method should you use?

On Ubuntu 26.04, the APT package already gives you Go 1.26, which is enough for most projects. On Ubuntu 24.04, the default Go 1.22 is old, so use golang-1.26-go if you want updates through APT, or the go.dev tarball if you always want the newest release. If you are still deciding whether to move the machine itself, see how to upgrade Ubuntu 24.04 to 26.04. For an editor with Go support, install Visual Studio Code on Ubuntu and add the Go extension; Go is also the language behind tools such as kubectl.

FAQ

Do I need to set GOROOT or GOPATH?

No. The go command works out GOROOT from its own location, and GOPATH defaults to ~/go. Run go env GOROOT GOPATH to see the values; with the APT package on Ubuntu 24.04 they were /usr/lib/go-1.22 and /root/go (for the root user) in our test.

Is golang-go the same as Go?

Yes. golang-go is Ubuntu’s package name for the Go toolchain. The program it installs is still called go.

Can I have two Go versions installed?

Yes. The APT, versioned, snap and tarball installs live in different folders. Whichever go comes first in PATH is the one that runs, which type -a go shows.

Advertisement