How to Install Go (Golang) on Ubuntu 26.04 and 24.04

Share

To install Go (Golang) on Ubuntu 26.04 or 24.04, use APT when Ubuntu’s packaged version meets your project’s needs, or the official Go archive for a current upstream release. A Canonical-maintained Snap is another option if you want managed updates.

Go is an open-source programming language created at Google, often used for command-line tools and web services. Golang is a common nickname for the same language. Follow one installation method below, then build and run your first program. If a step fails, leave a comment with the error or contact us.

Before you begin
  • Use Ubuntu 26.04 or 24.04 Desktop or Server, internet access and an account with sudo access. Terminal examples use Bash.
  • Choose one main installation method. Several copies can coexist, but your PATH decides which one runs.
  • Check your project’s required Go version. For an existing project, read the go and optional toolchain lines in its go.mod file.
  • Run project commands as your normal user. You do not need sudo to compile a program or install a tool into your own account.

1. Choose a Go installation method

Method Use it when Updates
Ubuntu APT package You want Ubuntu package management and the packaged compiler meets your project requirement. Updates arrive through Ubuntu’s repositories.
Official Go archive You need a specific upstream version or the current upstream stable release. Supports the amd64 and arm64 examples below. Download, verify and replace the compiler yourself.
Canonical-maintained Go Snap You want a current packaged toolchain with managed updates and accept classic confinement. Snap refreshes it automatically; the selected channel controls the release track.

Ubuntu’s default golang-go package selects Go 1.26 on 26.04 and Go 1.22 on 24.04, according to the 26.04 and 24.04 package listings. These are release branches, not exact patch versions. Check the local candidate before installing.

Check your Ubuntu release, architecture and existing Go

Open a terminal, using Ctrl+Alt+T on a normal Ubuntu desktop. Run these checks individually:

Ubuntu terminal
cat /etc/os-release
dpkg --print-architecture
type -a go
GOTOOLCHAIN=local go version

A command-not-found message is expected if Go is absent. amd64 means 64-bit Intel/AMD; arm64 means 64-bit ARM. The temporary GOTOOLCHAIN=local setting checks the bundled compiler without automatically switching to another toolchain.

2. Install Go with APT

Step 1: Refresh metadata and inspect the candidate

This refreshes package information without upgrading the whole system.

Ubuntu terminal
sudo apt update
apt-cache policy golang-go

Check for a real Candidate version and resolve repository errors first. The metapackage version may include an epoch such as 2:; verify the compiler itself after installing.

Step 2: Install the Ubuntu package

Install the compiler and its package dependencies:

Ubuntu terminal
sudo apt install golang-go

Review APT’s proposed changes before confirming. This method needs no custom /usr/local/go PATH entry. Skip the archive and Snap installation sections unless you intend to switch methods.

Step 3: Check the installed compiler

Confirm which command your shell finds and the bundled compiler version:

Ubuntu terminal
command -v go
GOTOOLCHAIN=local go version

A standard APT installation normally resolves through /usr/bin/go. On Ubuntu 24.04, expect the 1.22 branch from the default metapackage. If a project requires a newer release, choose the archive or Snap route, then check PATH order.

3. Install the official Go archive

This method installs Go under /usr/local/go and requires manual updates. The example pins Go 1.27.3, checked on 8 November 2026. For a later release, take both its filename and its matching SHA256 from the official Go downloads page. Never reuse a checksum with a different archive.

Step 1: Install download prerequisites

Install curl, trusted CA certificates and the archive tools:

Ubuntu terminal
sudo apt update
sudo apt install curl ca-certificates tar

Ubuntu supplies sha256sum through coreutils. Keep the following steps in the same terminal so the download variables remain available.

Step 2: Download and verify the matching archive

Copy the complete block. It selects amd64 or arm64 and stores the archive in a unique temporary directory.

Ubuntu terminal
download_go() {
  case "$(dpkg --print-architecture)" in
    amd64) go_arch=amd64; go_sha=65efbc80fdc1fa2cd2631cad5b481777a68e8725f34e89f50fc6ac714e379b40 ;;
    arm64) go_arch=arm64; go_sha=a06e99309dbcbdca1a8ccd2282c3ee146e55930886e26b4f1193269587165f49 ;;
    *) echo "Use go.dev/dl to select an archive for this architecture."; return 1 ;;
  esac
  go_file="go1.27.3.linux-${go_arch}.tar.gz"
  go_download_dir=$(mktemp -d) || return 1
  go_archive="$go_download_dir/$go_file"
  curl --fail --location --output "$go_archive" "https://go.dev/dl/$go_file" || return 1
  printf '%s  %s\n' "$go_sha" "$go_archive" | sha256sum --check || return 1
}
download_go

The final line must report OK. Stop if the download or checksum fails. Do not extract a failed or partially downloaded file. A checksum checks that the file matches the hash published by Go; obtain both from the official HTTPS site.

Step 3: Extract only into a fresh installation directory

The block refuses to overwrite an existing directory or symbolic link and verifies the file again before extraction.

Ubuntu terminal
install_go_archive() {
  if [ -e /usr/local/go ] || [ -L /usr/local/go ]; then
    echo "/usr/local/go exists. Use the update section first."
    return 1
  fi
  [ -f "${go_archive:-}" ] && [ -n "${go_sha:-}" ] || return 1
  printf '%s  %s\n' "$go_sha" "$go_archive" | sha256sum --check || return 1
  sudo tar -C /usr/local -xzf "$go_archive" || return 1
  GOTOOLCHAIN=local /usr/local/go/bin/go version
}
install_go_archive

Expect go version go1.27.3 linux/amd64 or linux/arm64. Never unpack a new release over an old Go tree. If extraction fails, stop and inspect the partial /usr/local/go directory before retrying; the downloaded archive remains available in the temporary directory.

Step 4: Add the compiler to this terminal

Put the new compiler before other Go installations in PATH:

Ubuntu terminal
export PATH="/usr/local/go/bin:$PATH"
hash -r
command -v go
GOTOOLCHAIN=local go version

The path should now be /usr/local/go/bin/go. The variable change affects this terminal and its child processes only.

Step 5: Save the PATH setting for future logins

Open your own login profile without overwriting it:

Ubuntu terminal
nano "$HOME/.profile"

Use another text editor if nano is unavailable. Add the following line once, or update the existing Go line. Save, then sign out and back in so desktop applications inherit it too. A Bash login that reads a custom ~/.bash_profile must also source ~/.profile. Other shells and system services have their own environment configuration.

Line to add to ~/.profile
export PATH="/usr/local/go/bin:$PATH"

After the new login, repeat command -v go and GOTOOLCHAIN=local go version. Go normally detects its own installation root; do not set GOROOT as part of a routine installation.

4. Alternative: install Go with Snap

Step 1: Check Snap and its package information

Ubuntu Desktop normally includes Snap support. Check the publisher and available stable channel:

Ubuntu terminal
snap version
snap info go

The verified publisher is Canonical. If Snap is missing, follow the Snap setup instructions for Ubuntu first. Classic confinement gives this development tool broad access to your system under your user permissions.

Step 2: Install and verify

Install from the default stable channel:

Ubuntu terminal
sudo snap install go --classic
/snap/bin/go version
command -v go
GOTOOLCHAIN=local go version

Your shell should select /snap/bin/go. If it finds an APT or archive installation instead, resolve that PATH conflict before starting a project. If /snap/bin is missing from PATH after setting up snapd, sign out and back in. The latest/stable channel can move to a newer major Go release.

5. Build and run your first Go program

Use these steps after completing one installation method. The example uses only Go’s standard library, so it does not fetch third-party source code.

Step 1: Create a new module and source file

Use a unique practice directory so these commands cannot replace an existing project file:

Ubuntu terminal
go_demo_dir=$(mktemp -d "$HOME/go-demo.XXXXXX")
cd "$go_demo_dir"
go mod init example.com/hello-ubuntu
cat > main.go <<'EOF'
package main

import "fmt"

func main() {
    fmt.Println("Go works on Ubuntu!")
}
EOF

A module groups your project and its dependencies. example.com/hello-ubuntu is a local example name; it does not create a website or upload your code. go mod init creates go.mod. Modern projects do not have to live inside GOPATH.

Step 2: Format and run the code

Run from the directory containing main.go and go.mod:

Ubuntu terminal
gofmt -w main.go
go run .

gofmt formats the source file in place. go run compiles and runs it. Expect the following line, without typing it as a command:

Go works on Ubuntu!
Step 3: Build a reusable executable

Build a program named hello-ubuntu, then run it:

Ubuntu terminal
go build -o hello-ubuntu .
./hello-ubuntu

The same message should appear. The ./ means to run the executable from this directory. It is a binary for your current operating system and architecture; compiling here does not automatically produce a Windows executable.

6. Find installed Go command-line tools

A tool installed with go install goes to GOBIN when that is set. Otherwise it goes to the bin directory under GOPATH, normally $HOME/go/bin. Check your actual settings:

Ubuntu terminal
go env GOBIN GOPATH GOROOT

With the default empty GOBIN and default GOPATH, run this line in your current terminal and add it once to your ~/.profile for future logins. If you configured a custom GOBIN or GOPATH, use its actual tool directory instead.

Line to add for user-installed tools
export PATH="$PATH:$HOME/go/bin"

You can test installation using the harmless practice program, from its module directory:

Ubuntu terminal
go install .
hello-ubuntu

This installs a user-level copy of the example. Do not use sudo for this command. For an external tool, follow its official module path and version instructions, using go install module/path@version. Updating the compiler does not rebuild tools you previously installed.

7. Update Go using the same installation method

APT: apply Ubuntu package updates

Ubuntu updates the numbered compiler packages behind the golang-go metapackage through normal package updates.

Ubuntu terminal
sudo apt update
sudo apt upgrade
GOTOOLCHAIN=local go version

Review the proposed transaction: apt upgrade can update other system packages too. A default package on Ubuntu 24.04 does not turn into the current upstream branch just because you refresh APT.

Snap: refresh the installed package

Snap normally refreshes automatically. To request a refresh and inspect the result:

Ubuntu terminal
sudo snap refresh go
snap list go
GOTOOLCHAIN=local /snap/bin/go version

Check the tracking channel using snap info go if your project needs a fixed major branch. Select an available supported version track deliberately; do not assume latest/stable stays on one major version.

Archive: keep a rollback copy before replacement

Download the desired new archive and verify its own checksum using the archive section first. Update the filename and hash together. Stop builds or maintenance jobs that use this compiler. Inspect the current path:

Ubuntu terminal
ls -ld /usr/local/go /usr/local/go.previous
GOTOOLCHAIN=local /usr/local/go/bin/go version

A missing /usr/local/go.previous is expected on the first update. Continue only when /usr/local/go is the real archive-installation directory, not a symlink or unrelated folder, and the backup destination does not exist. The following block moves the old compiler aside without deleting it:

Ubuntu terminal
if [ -d /usr/local/go ] && [ ! -L /usr/local/go ] &&
   [ ! -e /usr/local/go.previous ] && [ ! -L /usr/local/go.previous ]; then
  sudo mv -T -- /usr/local/go /usr/local/go.previous
else
  echo "Inspect the installation and backup paths before continuing."
fi

Only after the move succeeds, run the complete install_go_archive block from Step 3 again, in the same terminal holding the new archive variables. Verify the new version, rebuild the example and run your project’s tests. Do not rename your project directory or reuse a checksum from the old release.

Rollback if the new archive installation fails

Keep the previous compiler until the new one works. If a new or partial /usr/local/go exists, first inspect it and move it aside to an unused name such as /usr/local/go.failed. Stop if that destination already exists. Once /usr/local/go is absent, restore the backup:

Ubuntu terminal
sudo mv -T -- /usr/local/go.previous /usr/local/go
GOTOOLCHAIN=local /usr/local/go/bin/go version

Restore any project settings changed for the newer release and test again. Updating Go does not replace an already running compiled service; rebuild and redeploy that application through its normal process.

8. Fix common Go problems

Issue 1: go: command not found

For APT, check that golang-go installed successfully. For an archive, check /usr/local/go/bin/go and the compiler PATH line. For Snap, try /snap/bin/go version and start a fresh login. A new profile line does not change an already open terminal.

Issue 2: The wrong Go version runs

List all matching commands and compare the bundled compiler with the toolchain selected inside your project:

Ubuntu terminal
type -a go
GOTOOLCHAIN=local go version
go version
go env GOTOOLCHAIN GOROOT

An alias, version manager or earlier PATH entry may select another installation. Go 1.21 and later can also select or download a newer toolchain according to project settings. Go’s toolchain documentation explains this behavior. Change the intended installation or project requirement; do not blindly force an older go.mod version.

Issue 3: Permission denied or a root-owned module cache

Do not fix a build by running it with sudo. Use a project directory you own and inspect the cache locations:

Ubuntu terminal
go env GOPATH GOMODCACHE GOCACHE
ls -ld "$HOME/go" "$HOME/.cache/go-build"

A missing default directory can be normal before the first build. If earlier sudo commands created root-owned files, check each affected path and correct ownership only for your own project or cache. Do not recursively change ownership of system compiler directories.

Issue 4: go.mod file not found

Change into the project directory containing go.mod. For the practice project, use cd "$go_demo_dir" in the same terminal. For a genuinely new project, initialize a module once with go mod init. Do not initialize a second module inside an existing project just to hide the error.

Issue 5: Exec format error or checksum mismatch

An exec format error commonly means the compiler or built program targets a different CPU architecture or operating system. Check dpkg --print-architecture and select the matching Linux archive. A checksum mismatch means stop: download the file again and compare against the hash for that exact filename. Do not bypass verification.

Issue 6: A project needs a newer toolchain, or a download fails

Check the go.mod requirement and go env GOTOOLCHAIN. With automatic switching enabled, Go may download a required toolchain. With GOTOOLCHAIN=local, it fails when the bundled compiler is too old. Install an appropriate release or permit the documented project toolchain behavior. For network errors, check your connection, proxy and CA certificates; do not disable TLS or module verification.

9. Remove Go and undo your PATH changes

APT: preview the packages to remove

Removing only the golang-go metapackage may leave the numbered compiler installed. List the actual Go packages, then preview removing the chosen compiler.

Ubuntu terminal
dpkg-query -W 'golang*'
sudo apt -s remove golang-go golang-1.22-go golang-1.22-src

The removal example is for the default 24.04 installation. On 26.04, substitute golang-1.26-go and golang-1.26-src. Adjust names to your installed-package list. Review dependent packages in the simulation, then repeat without -s only when the plan is acceptable. Do not delete package-managed compiler files manually.

Snap: remove the package

Remove the Go Snap if that is the method you installed:

Ubuntu terminal
sudo snap remove go

Other Go installations can still provide a go command afterwards. Check type -a go.

Archive: inspect the installation before deleting it

Check that this exact directory is the manually extracted compiler and contains no project files you need:

Ubuntu terminal
ls -ld /usr/local/go
ls /usr/local/go

After confirming it is the archive installation you intend to remove, the next command permanently deletes that compiler tree. Stop builds using it first. Do not run it on a path used for another purpose.

Ubuntu terminal
sudo rm -rf -- /usr/local/go

Remove only the archive compiler’s /usr/local/go/bin entry from your profile, then start a new login session. Inspect retained go.previous or go.failed backups separately. Your source projects, module cache and user-installed tools are separate from the compiler. Do not delete ~/go as a routine uninstall step: it may contain work or tools you still need. Keep the user-tool PATH line if you still use that directory.

Helpful Go resources

Official documentation

Frequently asked questions

Are Go and Golang the same language?

Yes. The official name is Go. Golang is a common nickname that came from the original golang.org website. Ubuntu uses golang-go as the name of its default compiler package.

Which Go installation method should I use on Ubuntu?

Use APT when the Ubuntu-packaged compiler meets your project requirement. Choose the official archive for a specific upstream release and manual update control, or the Canonical-maintained Snap for managed updates. Choose one main installation and verify which go command your shell finds.

Do I need to set GOPATH or GOROOT?

Normally no. Go detects its compiler installation root and provides a default GOPATH under your home directory. Modern module-based projects can live outside GOPATH. You may need to add your user tool directory to PATH to run programs installed with go install.

Why does go version change inside a project?

Go can select a toolchain according to GOTOOLCHAIN and the go and toolchain settings in go.mod or go.work. Automatic selection may use a newer downloaded toolchain. GOTOOLCHAIN=local go version reports the compiler bundled with the go command selected by your shell.

Does installing Go require a full Ubuntu upgrade?

No. Refresh APT metadata and install the packages you need. A full system upgrade is not a prerequisite for installation. Review and apply routine security and package updates through your normal maintenance process.

Related Ubuntu guides: Install Visual Studio Code for editing projects, or check your Ubuntu version before choosing release-specific instructions.