Go (Golang) powers modern cloud infrastructure with its speed, concurrency, and scalable web services. Whether you build microservices, develop APIs, or compile system tools, Go provides a strict type system and a powerful standard library without unnecessary complexity. This guide shows you how to install Go on Ubuntu using the most reliable methods: the standard repository for stability, the PPA for easy updates, or the official tarball for the current feature set.
Choose Your Installation Method
Ubuntu includes Go in its default repositories, but the version depends on your release age. Developers needing the latest compiler features or security patches often require alternative methods. Compare your options below to select the best fit for your workflow:
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| APT | Default Repo | Fixed (older) | Automatic updates | Stability & simple projects |
| PPA | golang-backports | Latest Stable | Automatic updates | Devs on Ubuntu 22.04/24.04 |
| Tarball | Go.dev | Exact Version | Manual update | Complete version control |
| Source | Git Checkout | Any Commit | Manual build | Contributors & compiler devs |
Recommendation: I recommend the golang-backports PPA for Ubuntu 24.04 or 22.04 users who need a modern Go release managed by APT. Choose the Official Tarball if you require specific versions or need to run multiple Go installations side-by-side. Ubuntu 26.04 users can rely on the Default APT Repository, as it already ships a modern Go 1.25. Reserve building from Source for contributors or developers requiring custom compiler flags.
This guide covers Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. Commands work identically across all supported releases unless noted otherwise. The official tarball and source compilation methods install to
/usr/local/goand are independent of Ubuntu version.
Update Ubuntu System Packages
Before installing Go, update your package lists and upgrade existing packages to ensure your system has the latest security patches and avoid potential conflicts during installation.
sudo apt update && sudo apt upgrade
Install the required utilities for downloading and extracting archives. These packages are typically pre-installed on desktop systems, but minimal or server installations may lack them.
sudo apt install curl wget tar
Install Go from APT Repository
If you prefer automatic updates through your package manager and the repository version meets your requirements, install from the Ubuntu repositories. This method automates maintenance but may provide versions that trail official releases on older Ubuntu versions.
sudo apt install golang-go
Verify the installation by checking the version:
go version
Expected output varies by Ubuntu release:
go version go1.25 linux/amd64 # Ubuntu 26.04 (Resolute) go version go1.22 linux/amd64 # Ubuntu 24.04 (Noble) go version go1.18.1 linux/amd64 # Ubuntu 22.04 (Jammy)
If the repository version meets your requirements, proceed to the environment configuration section. Otherwise, continue with the PPA or official tarball installation for a newer Go release.
Install Go from Golang-Backports PPA
The golang-backports PPA is the most efficient way to get the latest stable Go version on Ubuntu 24.04 (Noble) and 22.04 (Jammy). Unlike the default repositories which freeze versions for stability (e.g., Go 1.18 on Ubuntu 22.04), this PPA provides active updates to the current release (Go 1.25+) while letting you manage installations with standard APT commands. It bridges the gap between the stability of APT and the freshness of manual tarballs.
Add the PPA Repository
Install the software properties package to manage independent software vendor (ISV) sources:
sudo apt install software-properties-common -y
Import the PPA to make newer Go packages available on your system:
sudo add-apt-repository ppa:longsleep/golang-backports -y
Update your package list to include the newly available Go releases:
sudo apt update
Install Go from the PPA
Install Go using the golang-go metapackage, which pulls in the latest available version:
sudo apt install golang-go
Verify the installation:
go version
go version go1.25 linux/amd64
The PPA provides versioned packages like
golang-1.24andgolang-1.25if you need a specific version. Install them withsudo apt install golang-1.24. These install to/usr/lib/go-1.24/bin/goand can coexist with other versions.
Switch Between Go Versions
If you have multiple Go versions installed from the PPA, use update-alternatives to switch between them. Register each installed version:
sudo update-alternatives --install /usr/bin/go go /usr/lib/go-1.24/bin/go 124
sudo update-alternatives --install /usr/bin/go go /usr/lib/go-1.25/bin/go 125
The numbers (124, 125) are priority values; higher numbers are preferred in auto mode. List the available alternatives:
sudo update-alternatives --list go
/usr/lib/go-1.24/bin/go /usr/lib/go-1.25/bin/go
Switch between versions interactively:
sudo update-alternatives --config go
There are 2 choices for the alternative go (providing /usr/bin/go). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/go-1.25/bin/go 125 auto mode 1 /usr/lib/go-1.24/bin/go 124 manual mode 2 /usr/lib/go-1.25/bin/go 125 manual mode Press <enter> to keep the current choice[*], or type selection number:
Enter the selection number corresponding to your desired version. Verify the change:
go version
Install Go from Official Tarball (Recommended)
Installing from the go.dev tarball gives you absolute control. This method installs Go identically on any Linux distribution. It is the preferred choice if you need to manage multiple specific versions or if you require an immediate update the moment a new security patch is released, without waiting for PPA maintainers.
Check System Architecture
Confirm your system architecture to ensure you download the correct package:
dpkg --print-architecture
amd64
The commands below automatically detect your architecture. Most systems use amd64 (64-bit Intel/AMD), but the commands also support arm64 (ARM servers, Raspberry Pi 4/5).
Download the Latest Go Release
The following command automatically detects your architecture and downloads the latest stable Go release from the official website:
cd /tmp
GO_ARCH=$(dpkg --print-architecture)
GO_TARBALL=$(curl -sL https://go.dev/dl/ | grep -oP "go[0-9]+\.[0-9]+\.[0-9]+\.linux-${GO_ARCH}\.tar\.gz" | head -1)
[ -z "$GO_TARBALL" ] && echo "Failed to detect Go version" && exit 1
echo "Downloading $GO_TARBALL..."
wget "https://go.dev/dl/$GO_TARBALL"
curl -sL: Fetches the download page silently and follows redirectsgrep -oP: Extracts the tarball filename using a Perl-compatible regexhead -1: Takes the first match, which is the latest stable release[ -z "$GO_TARBALL" ]: Guards against an empty variable if the page parsing fails
Alternatively, visit go.dev/dl to manually download a specific version if you need to match a project’s Go version requirements.
Remove Previous Go Installation
Remove any existing Go installation in /usr/local/go to prevent file conflicts and ensure a clean environment:
The following command deletes the existing Go installation directory. Ensure you do not have any custom data stored inside
/usr/local/gobefore proceeding.
sudo rm -rf /usr/local/go
Extract Go Archive
Extract the downloaded archive to /usr/local. This step creates the /usr/local/go directory containing the Go toolchain:
GO_ARCH=$(dpkg --print-architecture)
sudo tar -C /usr/local -xzf /tmp/go*.linux-${GO_ARCH}.tar.gz
rm -f /tmp/go*.linux-${GO_ARCH}.tar.gz
Verify the extraction succeeded:
/usr/local/go/bin/go version
go version go1.25.6 linux/amd64
Install Go from Source (Advanced)
Building Go from source gives you access to any release version and the ability to customize build flags. This method requires a bootstrap Go compiler because the Go toolchain is written in Go itself. The process works identically across Ubuntu 26.04, 24.04, and 22.04.
Install Build Prerequisites
Install Git on Ubuntu for cloning the source repository. Install GCC on Ubuntu to enable cgo support, which allows Go programs to call C libraries (similar to how Python ctypes or Java JNI bridge to native code):
sudo apt update
sudo apt install git gcc
If you only need pure Go programs without C library integration, you can skip GCC and set
CGO_ENABLED=0during the build. However, GCC is recommended for full functionality.
Download Bootstrap Compiler
Go 1.24 and newer require Go 1.22 or later as a bootstrap compiler. Since Ubuntu 24.04 ships Go 1.22 and Ubuntu 22.04 ships Go 1.18, download the official tarball as your bootstrap to ensure compatibility:
cd /tmp
GO_ARCH=$(dpkg --print-architecture)
curl -LO "https://go.dev/dl/go1.22.12.linux-${GO_ARCH}.tar.gz"
sudo tar -C /usr/local -xzf go1.22.12.linux-${GO_ARCH}.tar.gz
sudo mv /usr/local/go /usr/local/go-bootstrap
rm -f go1.22.12.linux-${GO_ARCH}.tar.gz
Verify the bootstrap compiler is available:
/usr/local/go-bootstrap/bin/go version
go version go1.22.12 linux/amd64
Clone Go Source Repository
Clone the Go source from the official repository and check out the release tag you want to build. The following command automatically detects the latest stable version and fetches only that version to minimize download size:
cd /tmp
GO_TAG=$(curl -sL https://go.dev/dl/ | grep -oP 'go[0-9]+\.[0-9]+\.[0-9]+\.src\.tar\.gz' | head -1 | sed 's/\.src\.tar\.gz//')
[ -z "$GO_TAG" ] && echo "Failed to detect Go version" && exit 1
echo "Cloning $GO_TAG..."
git clone --depth 1 --branch "$GO_TAG" https://go.googlesource.com/go goroot
To build a specific version, replace the
GO_TAGdetection with your desired tag (e.g.,GO_TAG=go1.24.3). See available tags at go.dev/dl.
Build Go from Source
Set the GOROOT_BOOTSTRAP environment variable to point to your bootstrap compiler, then run the build script:
export GOROOT_BOOTSTRAP=/usr/local/go-bootstrap
cd /tmp/goroot/src
./make.bash
The build takes approximately 2-5 minutes depending on your hardware. When complete, you see output similar to:
Building Go cmd/dist using /usr/local/go-bootstrap. (go1.22.12 linux/amd64) Building Go toolchain1 using /usr/local/go-bootstrap. Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1. Building Go toolchain2 using go_bootstrap and Go toolchain2. Building Go toolchain3 using go_bootstrap and Go toolchain2. Building packages and commands for linux/amd64. --- Installed Go for linux/amd64 in /tmp/goroot Installed commands in /tmp/goroot/bin
Install Built Go to System Location
Move the compiled Go tree to the standard installation location and clean up the bootstrap compiler:
sudo rm -rf /usr/local/go
sudo mv /tmp/goroot /usr/local/go
sudo rm -rf /usr/local/go-bootstrap
Verify the source-built installation:
/usr/local/go/bin/go version
go version go1.25.6 linux/amd64
The source-built Go installs to the same location as the tarball method (
/usr/local/go), so the environment variable configuration in the next section applies to both methods.
Configure Go Environment Variables
Go requires the PATH environment variable to include its binary directory. Additionally, setting GOPATH defines where Go stores downloaded modules and compiled binaries for your projects.
Temporary Configuration (Current Session)
To test Go immediately without modifying any configuration files, export the variables directly in your terminal. These settings last only until you close the terminal:
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
export GOPATH=$HOME/go
Permanent Configuration (Bash)
For permanent configuration with bash (the default shell on Ubuntu), add Go to your shell profile. The ~/.profile file is sourced by login shells and works reliably across all Ubuntu LTS versions:
grep -q '/usr/local/go/bin' ~/.profile || cat >> ~/.profile << 'EOF'
# Go programming language
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
export GOPATH=$HOME/go
EOF
The grep -q check prevents duplicate entries if you run the command again. Load the updated configuration into your current terminal session:
source ~/.profile
Alternatively, add the exports to
~/.bashrcif you want the configuration loaded for interactive non-login shells as well. However,~/.profileis the standard location for environment variables on Ubuntu systems.
Permanent Configuration (Zsh)
If you use zsh instead of bash, add the configuration to ~/.zshrc:
grep -q '/usr/local/go/bin' ~/.zshrc 2>/dev/null || cat >> ~/.zshrc << 'EOF'
# Go programming language
export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin
export GOPATH=$HOME/go
EOF
source ~/.zshrc
System-Wide Configuration (All Users)
To make Go available for all users on the system, create a dedicated profile script in /etc/profile.d/:
sudo tee /etc/profile.d/golang.sh > /dev/null << 'EOF'
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
EOF
This script runs automatically for all users during login. Log out and back in, or source it manually to apply immediately:
source /etc/profile.d/golang.sh
Verify Environment Configuration
Regardless of which configuration method you chose, verify Go is accessible and check the installed version:
go version
go version go1.25.6 linux/amd64
Version numbers shown in this guide reflect the latest stable release at the time of writing. Your output may show a newer version, which is expected as Go releases updates regularly.
Confirm the environment variables are set correctly:
go env | grep -E '^GO(PATH|ROOT)='
GOPATH='/home/username/go' GOROOT='/usr/local/go'
GOROOT: Location of the Go installation itself (/usr/local/go). You rarely need to modify this.GOPATH: Your personal workspace (~/go) where Go stores downloaded dependencies, compiled packages, and any tools you install withgo install. Think of it like npm’snode_modulesbut user-wide rather than per-project.
Verify Installation with Hello World
Create a simple Go program to confirm the installation works correctly. This test verifies that the compiler runs, modules initialize properly, and the build process completes successfully.
Create a project directory and initialize a Go module:
mkdir -p ~/go-hello && cd ~/go-hello
go mod init hello
go: creating new go.mod: module hello
Create the main program file:
cat > hello.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
EOF
Build and run the program:
go build -o hello
./hello
Hello, World!
If you see the output above, Go is correctly installed and configured. You can now develop Go applications on your Ubuntu system.
Clean up the test project when finished:
cd ~ && rm -rf ~/go-hello
Update Go to a New Version
Go releases occur regularly with security patches and new features. The update process depends on your installation method.
Update APT or PPA Installation
If you installed Go via APT or the PPA, update through your package manager:
sudo apt update
sudo apt install --only-upgrade golang-go
Update Tarball Installation
Check your current version:
go version
Download and install the latest release:
cd /tmp
GO_ARCH=$(dpkg --print-architecture)
GO_TARBALL=$(curl -sL https://go.dev/dl/ | grep -oP "go[0-9]+\.[0-9]+\.[0-9]+\.linux-${GO_ARCH}\.tar\.gz" | head -1)
[ -z "$GO_TARBALL" ] && echo "Failed to detect Go version" && exit 1
wget "https://go.dev/dl/$GO_TARBALL"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go*.linux-${GO_ARCH}.tar.gz
rm -f /tmp/go*.linux-${GO_ARCH}.tar.gz
Verify the update completed successfully:
go version
go version go1.25.6 linux/amd64
Your existing Go projects and installed packages in
$GOPATHremain intact after updating. The Go toolchain maintains backward compatibility, so projects built with older versions typically compile without modification.
Update Script for Source-Compiled Go
If you installed Go from source and prefer an automated update process, create the following script. It detects the latest version, downloads and compiles it using your existing Go installation as the bootstrap compiler:
cat > ~/update-go-source.sh << 'SCRIPT'
#!/bin/bash
set -e
# Refuse to run as root
if [ "$(id -u)" -eq 0 ]; then
echo "Run this script as a regular user (it uses sudo only for install steps)."
exit 1
fi
# Check required build tools
for cmd in git curl; do
if ! command -v $cmd > /dev/null; then
echo "Error: $cmd is missing; install it to continue."
exit 1
fi
done
# Get current and latest versions
CURRENT_VERSION=$(go version 2>/dev/null | grep -oP 'go[0-9]+\.[0-9]+\.[0-9]+' || echo "none")
LATEST_TAG=$(curl -sL https://go.dev/dl/ | grep -oP 'go[0-9]+\.[0-9]+\.[0-9]+\.src\.tar\.gz' | head -1 | sed 's/\.src\.tar\.gz//')
if [ -z "$LATEST_TAG" ]; then
echo "Error: Could not detect latest Go version from go.dev"
exit 1
fi
echo "Current version: $CURRENT_VERSION"
echo "Latest version: $LATEST_TAG"
if [ "$CURRENT_VERSION" = "$LATEST_TAG" ]; then
echo "Current Go version matches latest stable release."
exit 0
fi
echo "Updating to $LATEST_TAG..."
cd /tmp
# Use current Go as bootstrap
export GOROOT_BOOTSTRAP=/usr/local/go
# Clone and build
rm -rf goroot
echo "Cloning source repository..."
git clone --depth 1 --branch "$LATEST_TAG" https://go.googlesource.com/go goroot
cd goroot/src
echo "Building Go (this may take 2-5 minutes)..."
./make.bash
# Install
echo "Installing..."
sudo rm -rf /usr/local/go.bak
sudo mv /usr/local/go /usr/local/go.bak
sudo mv /tmp/goroot /usr/local/go
sudo rm -rf /usr/local/go.bak
echo "Successfully updated to $(/usr/local/go/bin/go version)"
SCRIPT
chmod +x ~/update-go-source.sh
Run the update script manually when you want to upgrade:
~/update-go-source.sh
Current version: go1.25.5 Latest version: go1.25.6 Updating to go1.25.6... Cloning source repository... Building Go (this may take 2-5 minutes)... Installing... Successfully updated to go version go1.25.6 linux/amd64
Avoid automating this script with cron. Source compilation can fail due to network issues, missing dependencies after system updates, or breaking changes between major versions. Run the script manually so you can monitor the output and address any problems before they affect your development environment.
Troubleshoot Common Go Issues
Command Not Found After Installation
If you run go version and see “command not found,” your shell cannot locate the Go binary.
bash: go: command not found
Confirm Go is correctly installed by checking if the binary exists:
ls -la /usr/local/go/bin/go
A successful result shows the binary with its permissions and size:
-rwxr-xr-x 1 root root 16441344 Nov 12 18:02 /usr/local/go/bin/go
If you see “No such file or directory,” Go is not installed. Return to the installation section and repeat the tarball extraction. When the file exists but the command still fails, check whether your shell profile includes the Go path:
grep "go/bin" ~/.profile
No output indicates the export line is missing. Add it:
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.profile
source ~/.profile
Verify the fix worked:
go version
go version go1.25.6 linux/amd64
Version Conflict Between APT and Tarball
If you previously installed Go via APT and then installed the official tarball, both versions may conflict. Remove the APT package first:
sudo apt purge golang-go golang-src
sudo apt autoremove
Verify only the tarball version remains:
which go
go version
/usr/local/go/bin/go go version go1.25.6 linux/amd64
GOPATH Permission Issues
If go install fails with permission errors, ensure GOPATH points to a user-writable directory:
go env GOPATH
ls -la $(go env GOPATH)
The GOPATH directory should be owned by your user. If it does not exist, Go creates it automatically on first use. If permissions are incorrect, fix them:
sudo chown -R $USER:$USER ~/go
Module Download Errors
If go get or go mod download fails with network errors, check your proxy settings:
go env | grep PROXY
GOPROXY='https://proxy.golang.org,direct' GONOPROXY='' GOPRIVATE=''
The default GOPROXY setting works for most users. If you are behind a corporate proxy or firewall, you may need to configure HTTP_PROXY and HTTPS_PROXY environment variables, or set GOPROXY=direct to bypass the Go module proxy.
Remove Go from Ubuntu
Removal steps depend on your installation method.
Remove APT or PPA Installation
If you installed Go via APT or the PPA, remove it with the package manager:
sudo apt purge golang-go golang-src golang-1.24 golang-1.25
sudo apt autoremove
If you added the golang-backports PPA and no longer need it:
sudo add-apt-repository --remove ppa:longsleep/golang-backports -y
If you configured update-alternatives for Go, remove those entries:
sudo update-alternatives --remove-all go 2>/dev/null || true
Remove Tarball or Source-Compiled Installation
Both the official tarball and source compilation methods install Go to /usr/local/go, so the removal process is identical. Remove the installation directory:
The following command deletes the existing Go installation directory. Ensure you do not have any custom data stored inside
/usr/local/gobefore proceeding.
sudo rm -rf /usr/local/go
If you built from source and the bootstrap compiler still exists, remove it as well:
sudo rm -rf /usr/local/go-bootstrap
Remove the update script if you created one:
rm -f ~/update-go-source.sh
Remove Environment Configuration
Remove the Go-related exports from your shell profile. Edit the appropriate file based on your shell and configuration method:
- Bash users: Edit
~/.profileor~/.bashrc - Zsh users: Edit
~/.zshrc - System-wide configuration: Remove
/etc/profile.d/golang.sh
For user-level configuration, open your profile file:
nano ~/.profile
Delete the lines containing /usr/local/go/bin and GOPATH, then save and exit.
If you configured Go system-wide, remove the profile script:
sudo rm -f /etc/profile.d/golang.sh
Remove Go Workspace (Optional)
The
~/godirectory contains downloaded modules, compiled binaries, and build cache from your projects, including any Go tools you installed withgo install. The following command permanently deletes this workspace. Back up any important code before running this.
Remove the Go workspace directory and build cache if you no longer need cached modules and installed binaries:
rm -rf ~/go
rm -rf ~/.cache/go-build
Verify Go is completely removed by starting a new terminal session and checking:
command -v go || echo "Go not found"
Go not found
Common Questions (FAQ)
APT installs Go from Ubuntu or PPA repositories, offering easier updates via system commands but potentially older versions. The Tarball method involves manually downloading binaries from Google, providing the absolute latest version and isolation from system packages, but requires manual updates.
For modern Go development (using Go Modules), explicitly setting GOPATH is often optional as it defaults to $HOME/go. However, defining it ensures your shell knows exactly where to look for installed binaries and downloaded dependencies, preventing “command not found” errors for user-installed tools.
If installed via PPA, use the update-alternatives command to switch the system-wide default. If using tarballs, you can manually update your PATH variable in your shell profile to point to the desired version directory, or use a tool like GVM (Go Version Manager) for frequent switching.
This typically happens because your shell profile hasn’t been reloaded. The changes to PATH only apply to new terminal sessions. Run source ~/.profile (or source ~/.bashrc / source ~/.zshrc) to apply them immediately to your current window.
Conclusion
You have successfully installed Go on Ubuntu using the method that best matches your needs, whether that is the stability of the default repository, the freshness of the PPA, or the precision of the tarball. Your environment is now configured with the correct GOPATH and PATH variables, ready for development. From here, you can start building applications, explore the Go documentation, or integrate your setup with Git on Ubuntu and Docker on Ubuntu for a complete DevOps workflow.