Installing and Updating Go on Ubuntu¶
Go is distributed as a self-contained tarball from the official Go website.
The recommended installation method is a manual tarball install to /usr/local/go, giving you full control over the version and no dependency on system package managers.
What It Is¶
The official Go toolchain includes:
go— the build tool, test runner, and module managergofmt— the standard code formattergodoc— documentation viewer- The Go standard library
The canonical install path is /usr/local/go, with the Go binary at /usr/local/go/bin/go.
When to Use It¶
Use this method when:
- You need a specific Go version not available in
apt - You want reproducible toolchain installations across machines
- You are upgrading from an older Go version
- You are setting up a CI environment or developer workstation on Ubuntu
Core Commands¶
Check the Current Go Version¶
go version
Why it matters:
- Confirms the active version before upgrading or after installing
- Verifies the binary in
PATHis the one you expect
Find the Latest Go Version¶
Check the available releases at https://go.dev/dl/ or use curl:
curl -s https://go.dev/VERSION?m=text
Why it matters:
- Gives you the exact version string to use in the download URL
- Avoids manually browsing the release page
Download the Go Tarball¶
GO_VERSION=1.24.1
curl -LO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
Why it matters:
curl -Lfollows redirects from the official download URL-Osaves the file using the remote filename- Pinning
GO_VERSIONmakes the command auditable and repeatable
Verify the Download Checksum¶
sha256sum go${GO_VERSION}.linux-amd64.tar.gz
Compare the output against the checksum listed at https://go.dev/dl/ for the release.
Why it matters:
- Detects corrupted downloads before installing
- Confirms the binary matches the published release
Remove the Previous Go Installation¶
sudo rm -rf /usr/local/go
Why it matters:
- The official upgrade method is a full replacement — no in-place upgrade
- Leaving the old directory causes a mixed installation if you extract on top
Warning
This command deletes the current Go toolchain. Only run it after downloading the new tarball and confirming a valid checksum.
Extract and Install¶
sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
Why it matters:
- Extracts the tarball to
/usr/local, creating/usr/local/go -Csets the target directory; the tarball itself contains ago/subdirectory- No build step required — Go ships as a pre-compiled binary
Add Go to PATH¶
If Go is not yet in your PATH, add it to your shell profile:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
source ~/.profile
For Zsh users:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.zshrc
source ~/.zshrc
Why it matters:
- The Go binary is at
/usr/local/go/bin/go; it must be onPATHto invoke it by name sourceapplies the change immediately without opening a new shell
Configure GOPATH (Optional but Recommended)¶
echo 'export GOPATH=$HOME/go' >> ~/.profile
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.profile
source ~/.profile
Why it matters:
GOPATH/binis wherego installplaces binaries (e.g.,golangci-lint,dlv)- Setting it explicitly avoids relying on the default
~/gopath being implicit
Verify the Installation¶
go version
go env GOROOT
go env GOPATH
Why it matters:
go versionconfirms the installed versiongo env GOROOTconfirms the toolchain root matches/usr/local/gogo env GOPATHconfirms the workspace path is configured correctly
Real-World Example¶
Scenario: upgrade from Go 1.22 to Go 1.24.1 on an Ubuntu developer workstation.
- Confirm the current version:
go version
# go version go1.22.0 linux/amd64
- Set the target version and download the tarball:
GO_VERSION=1.24.1
curl -LO "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz"
- Verify the checksum against https://go.dev/dl/:
sha256sum go${GO_VERSION}.linux-amd64.tar.gz
- Remove the old installation:
sudo rm -rf /usr/local/go
- Extract the new version:
sudo tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz
- Verify the upgrade succeeded:
go version
# go version go1.24.1 linux/amd64
go env GOROOT
# /usr/local/go
- Clean up the downloaded tarball:
rm go${GO_VERSION}.linux-amd64.tar.gz
Debugging Pattern¶
Use this sequence when Go is not working after install or upgrade:
- Check if the binary is found:
which go
# Expected: /usr/local/go/bin/go
- If
which goreturns nothing, checkPATH:
echo $PATH | tr ':' '\n' | grep go
- Check if the profile was sourced:
source ~/.profile # or ~/.zshrc for Zsh
which go
- Confirm the installation directory exists:
ls /usr/local/go/bin/go
- Check
GOROOTandGOPATH:
go env GOROOT
go env GOPATH
Decision shortcuts:
go: command not found: binary not onPATH; source your profile or open a new shellgo env GOROOTshows wrong path: another Go installation is taking precedence; check/usr/bin/goorsnap-installed Gopermission deniedon/usr/local/go: extraction ran withoutsudo
Common Pitfalls¶
- Extracting the tarball on top of an existing
/usr/local/godirectory without removing it first — causes mixed versions - Using
apt install golang-go— the APT package is frequently multiple versions behind the current release - Forgetting to source the shell profile after modifying
PATH— the new binary is not visible in the current session - Not adding
$GOPATH/bintoPATH— binaries installed withgo installare not accessible by name - Skipping the checksum verification — risks installing a corrupted or tampered binary
- Installing as root but running as a regular user without
PATHalignment — leads to version mismatches betweensudo goandgo