How to Install Go (Golang) on Ubuntu 26.04

Installing Go (Golang) on Ubuntu 26.04 is straightforward whether you use the Ubuntu repository for convenience or the official tarball for the latest version. This guide walks you through both methods, covers GOPATH configuration, and verifies your setup with a simple Go program.

In this tutorial you will learn:

  • How to install Go on Ubuntu 26.04 from the default repository
  • How to install Go as a snap package from Canonical
  • How to install the latest Go version from the official tarball
  • How to configure GOPATH and Go environment variables
  • How to write and run a basic Go program
  • How to upgrade and remove Go installations
Abstract illustration representing Go programming language installation on Ubuntu Linux with gopher mascot elements and terminal visuals
Installing and configuring Go (Golang) on Ubuntu 26.04

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software Go (Golang) 1.26+ (repository or official tarball)
Other Privileged access to your Linux system as root or via the sudo command. Internet connection for downloading packages.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user
TL;DR
Install Go on Ubuntu 26.04 from the repository with apt, or download the official tarball for the latest version.

Quick Steps to Install Go (Golang) on Ubuntu 26.04
Step Command/Action
1. Install from repository $ sudo apt install golang-go
2. Or install as a snap $ sudo snap install go --classic
3. Or install from tarball $ sudo tar -C /usr/local -xzf go1.26.1.linux-amd64.tar.gz
4. Set PATH (tarball method) export PATH=$PATH:/usr/local/go/bin in ~/.profile
5. Verify installation $ go version

Understanding Go Installation Methods on Ubuntu 26.04

Before you install Go (Golang) on Ubuntu 26.04, it is important to understand the three main installation methods available. Each approach has distinct advantages depending on your needs.

The Ubuntu repository method uses apt to install Go from the official Ubuntu 26.04 package archive. This is the simplest approach and integrates with your system’s package management. However, the repository version may lag behind the latest upstream release.

The snap method installs Go as a snap package maintained by Canonical. This provides a recent Go version with automatic background updates and works on any Linux distribution that supports snap. Since Ubuntu 26.04 ships with snap support out of the box, this is a convenient middle ground between the repository and tarball methods.

The official tarball method downloads Go directly from go.dev. This gives you access to the newest Go release and is the method recommended by the Go project itself. Consequently, this is the preferred choice for developers who need a specific version or want full manual control.

WHICH METHOD TO CHOOSE
Use the snap for the easiest path to a current Go version with automatic updates. Choose the official tarball if you need a specific release or want full manual control. The repository method is suitable if you prefer apt for all package management.

Installing Go from Ubuntu Repository

The fastest way to install Go on Ubuntu 26.04 is through the default package repository. This method requires minimal effort and keeps Go updated alongside your other system packages.

  1. Update the package index: Start by refreshing your package lists to ensure you get the latest available version:
    $ sudo apt update
  2. Install Go: Use apt to install the golang-go package. You can use the sudo command to gain the necessary privileges:
    $ sudo apt install golang-go
  3. Verify the installation: Confirm that Go is installed correctly by checking its version:
    $ go version

    You should see output similar to:

    go version go1.26.x linux/amd64
Terminal output showing Go installation from Ubuntu repository with apt and go version command displaying go1.26.0
Installing Go using apt and verifying with go version on Ubuntu 26.04

That is all you need for the repository method. Go is ready to use immediately, and your PATH is configured automatically.

Installing Go as a Snap Package

The snap package provides a convenient way to install Go on Ubuntu 26.04 with a single command. The Go snap is maintained by Canonical and receives automatic updates.

  1. Install the Go snap: The --classic flag is required because Go needs access to system resources outside the snap sandbox:
    $ sudo snap install go --classic

    Once complete, you should see confirmation output:

    go 1.26.1 from Canonical✓ installed
  2. Verify the installation: Check that the snap-installed Go is accessible:
    $ go version

    Expected output:

    go version go1.26.1 linux/amd64
Terminal output showing Go 1.26.1 installation via snap install go --classic command with version verification
Installing Go 1.26.1 as a snap package from Canonical on Ubuntu 26.04

The snap method automatically manages PATH configuration, so Go is ready to use right away. Additionally, snap handles version updates in the background without any manual intervention.

Installing Go from Official Tarball on Ubuntu 26.04

For the latest Go release, download the official tarball directly from the Go project. This method gives you full control over which version is installed.

  1. Remove any existing Go installation: If you previously installed Go from a tarball or another source, remove it first to avoid conflicts:
    $ sudo rm -rf /usr/local/go
  2. Download the latest Go tarball: Visit go.dev/dl to find the latest version. Then download it using wget:
    $ wget https://go.dev/dl/go1.26.1.linux-amd64.tar.gz

    Replace go1.26.1 with the latest version number shown on the download page.

  3. Extract the tarball to /usr/local: This is the standard location for manually installed Go:
    $ sudo tar -C /usr/local -xzf go1.26.1.linux-amd64.tar.gz

    This creates the /usr/local/go directory containing the entire Go distribution.

  4. Add Go to your PATH: Open your ~/.profile file and add the Go binary path:
    $ echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile
  5. Apply the changes: Load the updated profile in your current session:
    $ source ~/.profile
  6. Verify the installation: Confirm the tarball version is active:
    $ go version

    Expected output:

    go version go1.26.1 linux/amd64

IMPORTANT
Do not extract the tarball into an existing /usr/local/go directory. Always remove the previous installation first with sudo rm -rf /usr/local/go before extracting a new version. Overlapping files can produce a broken installation.

Terminal showing Go 1.26.1 tarball download with wget, extraction with tar, PATH configuration, and go version verification
Downloading and installing Go 1.26.1 from the official tarball on Ubuntu 26.04

Configuring Your Go Environment

Go on Ubuntu 26.04 works out of the box with sensible defaults. You can inspect the key environment variables with:

$ go env | grep -E 'GOPATH|GOROOT|GOBIN'
GOBIN=''
GOPATH='/home/linuxconfig/go'
GOROOT='/usr/local/go'

GOROOT points to the Go installation directory, and GOPATH (~/go by default) is where Go stores downloaded modules and compiled binaries. GOBIN is empty, which means Go places binaries in $GOPATH/bin.

The one thing Go does not do automatically is add $GOPATH/bin to your shell PATH. This matters as soon as you install Go tools with go install. Here is a practical example using goimports, a popular tool that automatically manages import statements in Go source files:

  1. Install a Go tool: Use go install to download and compile goimports:
    $ go install golang.org/x/tools/cmd/goimports@latest

    The binary is placed in $GOPATH/bin, but your shell does not know about that directory yet.

  2. Attempt to run the tool: Try running the newly installed tool:
    $ goimports --help
    Command 'goimports' not found, but can be installed with:
    sudo apt install golang-golang-x-tools

    The command fails because $GOPATH/bin is not in your PATH. Ignore the apt suggestion since you already have the tool installed.

  3. Add GOPATH bin to your PATH: Append the GOPATH bin directory to your ~/.profile and reload it:
    $ echo 'export PATH=$PATH:$(go env GOPATH)/bin' >> ~/.profile
    $ source ~/.profile
  4. Run the tool again: The command now works as expected:
    $ goimports --help
    usage: goimports [flags] [path ...]
      -d    display diffs instead of rewriting files
      -e    report all errors (not just the first 10 on different lines)
      -format-only
            if true, don't fix imports and only format...
Terminal showing go install goimports command, goimports not found error, PATH fix, and successful goimports --help output
Demonstrating GOPATH/bin PATH configuration by installing and running goimports on Ubuntu 26.04

DID YOU KNOW
Since Go 1.16, module mode is enabled by default. You no longer need to work inside GOPATH/src. You can create projects anywhere on your filesystem and use go mod init to manage dependencies.

Writing and Running Your First Go Program

With Go installed and configured on your Ubuntu 26.04 system, verify everything works by creating a simple Go program.

  1. Create a project directory: Make a new directory for your first Go project:
    $ mkdir -p ~/linuxconfig_project
    $ cd ~/linuxconfig_project
  2. Initialize a Go module: Every Go project uses modules for dependency management. Initialize one now:
    $ go mod init linuxconfig_project

    This creates a go.mod file in your project directory.

  3. Create the Go source file: Use your preferred text editor to create main.go:
    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Greetings from LinuxConfig.org")
    }
  4. Run the program: Execute the program directly with go run:
    $ go run main.go
    Greetings from LinuxConfig.org
  5. Build a compiled binary: Alternatively, compile the program into a standalone executable:
    $ go build -o linuxconfig_project main.go
    $ ./linuxconfig_project
    Greetings from LinuxConfig.org

    The go build command produces a statically linked binary that you can distribute without requiring Go on the target machine.

Terminal showing Go project creation with go mod init, main.go source code, go run and go build producing Greetings from LinuxConfig.org output
Creating, running, and building a Go program on Ubuntu 26.04

Managing Go Versions

Over time you may need to upgrade Go or remove it from your Ubuntu 26.04 system. The process depends on which installation method you used.

Upgrading a Repository Installation

If you installed Go through apt, upgrading is handled by the system package manager:

$ sudo apt update && sudo apt upgrade golang-go

Keep in mind that repository updates depend on the Ubuntu package maintainers. Therefore, the latest upstream Go release may not be available immediately.

Upgrading a Snap Installation

The Go snap updates automatically in the background. To trigger a manual refresh:

$ sudo snap refresh go

Upgrading a Tarball Installation

To upgrade a tarball-based installation, remove the old version and extract the new one:

$ sudo rm -rf /usr/local/go
$ wget https://go.dev/dl/go1.XX.X.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xzf go1.XX.X.linux-amd64.tar.gz

Replace go1.XX.X with the desired version number. Your PATH configuration remains unchanged, so the new version is active immediately.

Removing Go Completely

To remove a repository installation:

$ sudo apt remove golang-go && sudo apt autoremove

To remove a snap installation:

$ sudo snap remove go

To remove a tarball installation:

$ sudo rm -rf /usr/local/go

Additionally, remove the PATH entries you added to ~/.profile and optionally delete the Go workspace:

$ rm -rf ~/go

Conclusion

You have successfully installed Go (Golang) on Ubuntu 26.04 and configured your development environment. Whether you chose the Ubuntu repository for its simplicity, the snap for automatic updates, or the official tarball for full version control, your system is now ready for Go development. You created a Go module, wrote your first program, and learned how to manage Go versions going forward. Additionally, you can install Git to start using version control with your Go projects right away.

Frequently Asked Questions

  1. What is the difference between golang-go and the official Go tarball on Ubuntu 26.04? The golang-go package comes from the Ubuntu repository and is managed by apt. It may be slightly behind the latest release. The official tarball from go.dev always provides the newest stable version and is maintained by the Go team.
  2. Can I have both repository and tarball Go installations at the same time? This is not recommended because having two Go versions in your PATH causes confusion. If you want to switch methods, remove the existing installation first before installing with the other method.
  3. Where should I set the Go PATH – ~/.profile or ~/.bashrc? Use ~/.profile for login shells, which covers most use cases including terminal emulators on the Ubuntu 26.04 desktop. If you use a different shell such as Zsh, add the export to ~/.zshrc instead.
  4. Do I need to set GOPATH manually? No. Since Go 1.8, the default GOPATH is ~/go, and since Go 1.16, module mode is the standard. You only need to set GOPATH if you want to change the default workspace location.
  5. How do I check which Go version I am running? Run go version in your terminal. This displays the installed Go version, the operating system, and the architecture.