The Ubuntu package repos ship a Go compiler (golang-go) but it usually lags the upstream release by a minor version or two. For any project that needs the current standard library or new language features, installing Go directly from the official tarball at go.dev/dl is the recommended path. This guide covers both methods on Ubuntu 24.04 LTS and Debian 13, with dynamic version detection so the install pulls whatever is current when you run it.
Tested April 2026 on Ubuntu 24.04.4 LTS with Go 1.26.2 from the official tarball
Method 1: Install from the apt repository
If you’re on Ubuntu 24.04 or Debian 13 and don’t need the absolute latest Go, the packaged version is fine for most workloads. One command:
sudo apt update
sudo apt install -y golang-go
Check what version you got:
apt-cache policy golang-go
On Ubuntu 24.04 noble main the candidate is currently:
golang-go:
Installed: (none)
Candidate: 2:1.22~2build1
Version table:
2:1.22~2build1 500
500 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages
Go 1.22 is from early 2024. If that’s enough for your project, you can stop here. Otherwise, move to method 2 to get the current upstream release.
Method 2: Install from the go.dev tarball (recommended)
The official tarballs at go.dev/dl always have the latest stable and the release candidate. Go publishes a JSON API at https://go.dev/dl/?mode=json that lists the current releases, so a small shell command picks the latest automatically:
cd /tmp
LATEST=$(curl -sL 'https://go.dev/dl/?mode=json' \
| python3 -c 'import sys,json; print(json.load(sys.stdin)[0]["version"])')
echo "Latest Go: $LATEST"
On the day this guide was tested the detector returned:
Latest Go: go1.26.2
Download the linux-amd64 tarball. It’s around 64 MB:
curl -sSL -O "https://go.dev/dl/${LATEST}.linux-amd64.tar.gz"
ls -lh ${LATEST}.linux-amd64.tar.gz
The tarball lands as a 64 MB file in the current directory:
-rw-rw-r-- 1 ubuntu ubuntu 64M Apr 12 00:08 go1.26.2.linux-amd64.tar.gz
Step 3: Extract to /usr/local/go
The Go installation docs recommend extracting into /usr/local. This gives you a clean /usr/local/go/bin directory that only needs to be added to PATH once:
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf ${LATEST}.linux-amd64.tar.gz
The rm -rf removes any previous Go installation so you don’t end up with stale files. Run it before every upgrade.
Step 4: Add Go to the system PATH
Drop a tiny script in /etc/profile.d/ so every login shell gets Go on its PATH without needing to edit individual .bashrc files:
echo 'export PATH=$PATH:/usr/local/go/bin' | sudo tee /etc/profile.d/go.sh
sudo chmod 644 /etc/profile.d/go.sh
source /etc/profile.d/go.sh
Verify the Go compiler is on PATH and reports the right version:
go version
You should see the same version string you downloaded:
go version go1.26.2 linux/amd64
Step 5: Build a tiny hello world
A quick end-to-end smoke test: create a module, compile it, and run the binary:
mkdir -p /tmp/hello && cd /tmp/hello
go mod init hello
cat > main.go <<'EOF'
package main
import "fmt"
func main() {
fmt.Println("hello from Go")
}
EOF
go build -o hello main.go
./hello
The build completes silently if successful and produces a standalone hello binary in the current directory. Running it prints:
hello from Go
The binary is statically linked (no libc dependency) so you can copy it to another Linux host of the same architecture and run it directly.
Step 6: Set GOPATH and GOBIN (optional)
Modern Go uses modules by default so you rarely need to touch GOPATH, but when you install Go tools with go install they land in $GOBIN which defaults to $HOME/go/bin. Add that to your PATH too:
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin' >> ~/.bashrc
source ~/.bashrc
Now a tool like the static analyzer is a one-liner:
go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...
Step 7: Upgrading to a newer Go
When a new Go release lands, just re-run the detection + download + extract step from Step 2 and 3. The rm -rf wipes the old tree and the new one lands in the same place, so nothing in PATH changes and every existing build command still works.
For a fully automated refresh workflow, put the six lines from Steps 2-3 into a shell script and call it from a systemd timer. Or use a tool like gvm or asdf if you need multiple Go versions side by side on the same box.
Wrap up
The tarball install is the cleanest way to get the current Go on any Linux distro. No PPAs, no third-party repositories, no stale packages. For Go programs that need a database, see our PostgreSQL 17 install; for ones that ship as containers, our Docker CE reference. For CI runners building Go projects, pair this with our Ubuntu 22 to 24.04 upgrade guide to get on the current LTS first, then follow our systemctl reference for running Go services under systemd.