Searches for installing golang on Ubuntu, install golang ubuntu, install go ubuntu, golang ubuntu install, go linux download, go 1.21 download, or a concrete tarball name all map to the same choices: install golang-go from apt, install the go snap with classic confinement, install the official Linux tarball from go.dev/dl under /usr/local/go, or optionally compile a release tag from the upstream repository (Installing Go from source). Guides such as LinuxCapable, LinuxVox, and Cyberciti walk similar paths; this page compresses them into one decision-first flow, adds SHA256 verification for the tarball, calls out only-one-primary-install, and points go workspace seekers at go.work instead of legacy GOPATH trees.
Use 64-bit Ubuntu or another Debian-based system with
sudo. Commands usebash; onzsh, put PATH lines in~/.zshrcinstead of~/.bashrcwhere noted.
Pick one primary way to install Go on Ubuntu
Mixing a distro go with /usr/local/go is a common source of "wrong go version" bugs. Pick one channel as your default on PATH, then remove or disable the others (uninstall golang for deep cleanup).
| Method | Command idea | Typical tradeoff |
|---|---|---|
| apt | sudo apt install golang-go |
Easiest updates with apt upgrade, but the version tracks your Ubuntu release and may lag go.dev stable. |
| snap | sudo snap install go --classic |
Fresher builds from Canonical's snap; requires classic confinement for a full toolchain (Cyberciti snap section). |
| Tarball | Download go*.linux-*.tar.gz, extract to /usr/local/go |
Exact upstream version, works the same on every LTS; you replace the archive when you upgrade (official install doc). |
| From source | git clone + src/make.bash with a bootstrap Go |
For contributors, cherry-picks, or testing a release tag from the upstream repo; slower and you own upgrades (Installing Go from source). |
| PPA / backports | Third-party apt archives (example: community golang backports) | Can bring newer golang-go without manual tarballs; treat PPAs as extra trust and pin policy (LinuxCapable PPA discussion). |
Recommendation: tarball for teams that pin Go versions in CI; apt or snap when the packaged version meets go 1.xx in your go.mod.
Prerequisites (curl, tar, certificates)
Minimal images may lack tools the download steps assume. Install once:
sudo apt update
sudo apt install -y curl ca-certificates tarGit is required to build Go from source and for go get from VCS remotes; apt/snap/tarball installs do not need Git for the compiler alone.
Method A: apt and golang-go
sudo apt update
sudo apt install -y golang-go
go versionIf the reported version is too old for your go directive in go.mod, switch to the tarball or a maintained backport instead of forcing an unsupported compiler.
Method B: snap (go classic)
sudo snap install go --classic
go version--classic gives the snap the same broad filesystem access a normal deb install expects (LinuxVox and Cyberciti both highlight snap as a one-liner path). Remove with sudo snap remove go before moving to /usr/local/go.
Method C: official tarball (recommended for pinning)
1. Remove old /usr/local/go and conflicting packages
sudo rm -rf /usr/local/go
sudo apt remove --autoremove golang-go # optional, if you used apt before
sudo snap remove go # optional, if you used snap before2. Choose architecture (amd64 vs arm64)
dpkg --print-architecture
# or: uname -m # x86_64 -> amd64 tarball, aarch64 -> arm64 tarball3. Download from go.dev/dl
Pick the file that matches OS + CPU + version, for example go1.24.4.linux-amd64.tar.gz. You can copy the URL from the download list or resolve the current stable name:
cd /tmp
VERSION=$(curl -fsSL 'https://go.dev/VERSION?m=text' | head -n1)
ARCH=$(dpkg --print-architecture)
curl -fLO "https://go.dev/dl/${VERSION}.linux-${ARCH}.tar.gz"4. Verify SHA256 (same idea as Cyberciti shasum check)
On the go.dev/dl page, each .tar.gz has a published checksum. Compare manually:
sha256sum "${VERSION}.linux-${ARCH}.tar.gz"The printed hash must match the site exactly before you extract. This catches truncated downloads and mirror mistakes.
5. Extract to /usr/local
sudo tar -C /usr/local -xzf "${VERSION}.linux-${ARCH}.tar.gz"
/usr/local/go/bin/go version6. PATH (and optional go install bin directory)
Add the toolchain to your login profile (bashrc vs bash profile):
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.profile # optional: binaries from go install
source ~/.profile
go version$HOME/go/bin is the default install target for go install when GOPATH is unset (see go help install).
You normally do not set GOROOT for this layout. For GOPATH, defaults, and modules, read GOPATH vs GOROOT.
Method D: build Go from source (optional)
Use this when you need a tree built from the upstream repository (for example a release tag or a custom patch), not for everyday servers—tarball is simpler. Follow the official Installing Go from source page for bootstrap rules: you need an existing Go on PATH or set GOROOT_BOOTSTRAP to a complete earlier toolchain. Do not clone into $HOME/go if that directory is already your default GOPATH workspace; use something like /tmp/goroot-src or $HOME/sdk/go-src.
1. Prerequisites
sudo apt update
sudo apt install -y git ca-certificatesIf you want cgo in the built toolchain, install a C toolchain (for example build-essential) and omit CGO_ENABLED=0 below. A bootstrap Go must already work (from apt, snap, or /usr/local/go as in Method C).
2. Clone a release tag and compile
This example was run on linux/amd64 with bootstrap go1.24.4 at /usr/local/go, building go1.23.12 into /tmp/goroot-src (shallow clone keeps download smaller):
cd /tmp
rm -rf goroot-src
git clone --depth 1 --branch go1.23.12 https://go.googlesource.com/go goroot-src
export GOROOT_BOOTSTRAP=/usr/local/go
cd goroot-src/src
CGO_ENABLED=0 ./make.bashSuccessful end of make.bash looked like this on that machine:
Building Go cmd/dist using /usr/local/go. (go1.24.4 linux/amd64)
Building Go toolchain1 using /usr/local/go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.
Installed Go for linux/amd64 in /tmp/goroot-src
Installed commands in /tmp/goroot-src/bin
*** You need to add /tmp/goroot-src/bin to your PATH.3. Verify and wire PATH
/tmp/goroot-src/bin/go version
/tmp/goroot-src/bin/go env GOROOTExpected lines from the test run:
go version go1.23.12 linux/amd64
/tmp/goroot-srcTo use this build as your default for your user, prepend its bin before other Go installs in ~/.profile (order matters if you still have apt or snap go):
echo 'export PATH=/tmp/goroot-src/bin:$PATH' >> ~/.profile
source ~/.profile
go versionFor a permanent install path, rebuild after moving the tree or clone directly under a stable directory (for example sudo mv /tmp/goroot-src /usr/local/go-src and point PATH at /usr/local/go-src/bin). Run ./all.bash instead of ./make.bash if you also want to execute the full test suite (much slower).
Hello world with modules (LinuxVox-style sanity check)
mkdir -p ~/hello && cd ~/hello
go mod init example.com/helloCreate main.go:
package main
import "fmt"
func main() {
fmt.Println("Hello, Ubuntu")
}Run:
go run .That matches the "write a small program and run go run" verification pattern common across LinuxVox and LinuxCapable.
go workspace setup vs GOPATH workspace
- Modules:
go mod initin your project (default workflow today). go.work: multi-module editing; follow the official workspaces tutorial; this is what many "setup go workspace" searches intend.- GOPATH layout: legacy
src/bin/pkgunder$HOME/go; not required for new apps. See set GOPATH variable for historical context.
Summary
Installing golang on Ubuntu boils down to choosing apt golang-go, sudo snap install go --classic, the official go linux download tarball, or occasionally building from source with a bootstrap compiler, then making sure only one go binary leads your PATH. Install golang ubuntu workflows for production machines should add SHA256 verification before tar, export PATH=$PATH:/usr/local/go/bin, and confirm with go version. For go mod private repo or proxy settings after install, continue with Go environment variables and import private repos.
References
- Install Go — official instructions
- Installing Go from source
- Download Go
- Tutorial: Getting started with multi-module workspaces
- LinuxCapable — Go on Ubuntu (methods comparison)
- LinuxVox — Installing Go on Ubuntu
- Cyberciti — Install Go on Ubuntu (snap, apt, tarball + checksum)

