Install Go on Ubuntu: apt, snap, or official tarball (with checksum)

Tech reviewed: Deepak Prasad
Install Go on Ubuntu: apt, snap, or official tarball (with checksum)

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 use bash; on zsh, put PATH lines in ~/.zshrc instead of ~/.bashrc where 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:

text
sudo apt update
sudo apt install -y curl ca-certificates tar

Git 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

text
sudo apt update
sudo apt install -y golang-go
go version

If 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)

text
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.


1. Remove old /usr/local/go and conflicting packages

text
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 before

2. Choose architecture (amd64 vs arm64)

text
dpkg --print-architecture
# or: uname -m   # x86_64 -> amd64 tarball, aarch64 -> arm64 tarball

3. 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:

text
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:

text
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

text
sudo tar -C /usr/local -xzf "${VERSION}.linux-${ARCH}.tar.gz"
/usr/local/go/bin/go version

6. PATH (and optional go install bin directory)

Add the toolchain to your login profile (bashrc vs bash profile):

text
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

text
sudo apt update
sudo apt install -y git ca-certificates

If 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):

text
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.bash

Successful end of make.bash looked like this on that machine:

text
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

text
/tmp/goroot-src/bin/go version
/tmp/goroot-src/bin/go env GOROOT

Expected lines from the test run:

text
go version go1.23.12 linux/amd64
/tmp/goroot-src

To 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):

text
echo 'export PATH=/tmp/goroot-src/bin:$PATH' >> ~/.profile
source ~/.profile
go version

For 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)

text
mkdir -p ~/hello && cd ~/hello
go mod init example.com/hello

Create main.go:

go
package main

import "fmt"

func main() {
	fmt.Println("Hello, Ubuntu")
}
Output

Run:

text
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 init in 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/pkg under $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


Frequently Asked Questions

1. Should I use apt, snap, or the official tarball to install golang on Ubuntu?

Use apt or snap if a distro-managed version is new enough; use the official tarball when you need the latest stable upstream or an exact version, and verify the SHA256 from go.dev/dl.

2. Can I install go ubuntu two different ways at once?

You should pick one primary go binary on PATH; mixing /usr/bin/go from apt with /usr/local/go/bin from a tarball causes confusing go version output unless you carefully order PATH.

3. How do I verify the Linux tarball before extracting?

Download the .tar.gz and its published SHA256 from https://go.dev/dl/, then run sha256sum on the file and compare, or use sha256sum --check with a line in GNU coreutils format.

4. What architecture string do I need for go linux download?

Most PCs use linux-amd64.tar.gz; many ARM servers and 64-bit Raspberry Pi OS use linux-arm64.tar.gz; confirm with dpkg --print-architecture or uname -m.

5. Is go workspace setup the same as GOPATH?

No; go work and a go.work file coordinate multiple modules. GOPATH is a legacy workspace layout and default parent for some caches; modules use go.mod per project.

6. Does sudo snap install go need classic confinement?

The usual command is sudo snap install go --classic so the compiler can access the filesystem layouts it expects; always read current snap documentation for changes.

7. Why does building Go from source need another Go already installed?

The Go compiler is written in Go; the official bootstrap builds staged toolchains using an existing release on PATH or pointed to by GOROOT_BOOTSTRAP before producing the final tree in your clone directory (see Installing Go from source on go.dev).
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels across development, DevOps, …

  • Red Hat Certified System Administrator in Red Hat OpenStack
  • Certified Kubernetes Application Developer (CKAD)
  • Red Hat Certified Specialist in Ansible Automation
  • Go (programming language)
  • Python (programming language)
  • DevOps
  • Computer Security