How to Install GO (golang 1.25) in Ubuntu 24.04 | 22.04

Last updated: August 13, 2025 — 4 Comments

Go programming language announced the new 1.25 release on 12 August, 2025! Here’s the new features and how to install guide for Ubuntu & other Linux.

What’s New in Go 1.25:

  • New -http option in go doc command.
  • Add new -json option go version command.
  • New go.mod ignore directive to specify directories to ignore.
  • 2 new go vet analyzers: waitgroup and hostport.
  • New experimental garbage collector.
  • Default GOMAXPROCS to the number of cgroup CPU bandwidth limit in Linux, if it’s lower than an the number of logical CPUs available.
  • Generate debug information using DWARF 5.
  • New testing/synctest package
  • Remove the notion of core types in the language specification.
  • New encoding/json/v2 and encoding/json/jsontext packages.
  • Annotate anonymous memory mappings on Linux with Kernel that support it.
  • New -funcalign=N linker option.

See the announcement for more changes in Go 1.25.

How to Install Golang 1.25 in Ubuntu

1. Download the Linux Tarball

Go provides official Linux tarball for i386, amd64, arm64, and armv6l CPU architecture types. They are available to download at the link below:

In case you don’t know your system architecture type, press Ctrl+Alt+T to open terminal and run dpkg --print-architecture command to tell.

Or, run command to download the Linux tarball from command line (use amd64 package for modern Intel/AMD for example):

cd ~/Downloads && wget -c https://go.dev/dl/go1.25.0.linux-amd64.tar.gz

As time goes on, Go lang may release newer versions when you see this tutorial. In the case, change the URL (usually the part of version number) in last command accordingly.

2. Extract Go Tarball to /usr/local

NOTE: If you’re trying to update Go to newer version, it’s HIGHLY recommended to remove the old one (via command below) to avoid issues:

sudo rm -rf /usr/local/go

After downloaded the tarball, open terminal (Ctrl+Alt+T), and run commands:

  • Navigate to the folder that saved the tarball (usually Downloads folder):
    cd ~/Downloads
  • Then, extract the tarball to /usr/local directory:
    sudo tar -C /usr/local/ -xzf go1.25.0.linux-amd64.tar.gz

    Also replace package name go1.25.0.linux-amd64.tar.gz in the command according to which tarball you downloaded.

After successfully extracted the tarball, use ls /usr/local to verify. It will output a list of sub-folders including go.

3. Set PATH Environment Variable

a.) Add GOROOT to Your User PATH

To let your Ubuntu system know where to find Go command, user can add it to the PATH. And, here /usr/local/go is the GOROOT directory. You just need to add its bin sub-folder to the PATH.

Without logging out, run the command below to set PATH environment, which works until your close the terminal window or exit the command console.

export PATH=$PATH:/usr/local/go/bin

To make it permanent, open home folder, press Ctrl+H, then click edit the .profile file (or .bashrc). When file opens, add following lines and save it.

# set PATH so it includes /usr/local/go/bin if it exists
if [ -d "/usr/local/go/bin" ] ; then
    PATH="/usr/local/go/bin:$PATH"
fi

This works for current user only, and applies in next login.

To set the PATH environment variable for all users, create & edit a config file under /etc/profile.d directory instead. To do so, run command:

sudo nano /etc/profile.d/go.sh

Then, paste the same lines above. Press Ctrl+S to save, and Ctrl+X to exit. Also, log out and back in to apply.

b.) Add GOPATH to Your User PATH

Running go install command by default downloads & installs packages to go sub-folder (create automatically if not exist) in user home. It’s called GOPATH.

If you want to change GOPATH to another directory, for example .local/go, either use command below that works for current terminal or current command console:

export GOPATH=$HOME/.local/go

Or, edit the .profile file in user home and add the line in the end to make it permanent at next login.

To add GOPATH to your user PATH, here use the default GOPATH for example, either run command for current command console only:

export PATH=$PATH:$HOME/go/bin

Or, edit the .profile file and add following lines:

# Add GOPATH to PATH if it exists
if [ -d "$HOME/go/bin" ] ; then
    PATH="$HOME/go/bin:$PATH"
fi

NOTE: The GOPATH directory may NOT exist out-of-the-box. You need to log out and back in to apply it to user PATH on the folder creation (usually first time running go install command).

Golang also has many other environment options, you may run go env command to print them, and run similar commands above to change the directories.

Create your First Go program

When done setting PATH Environment Variable, you can run command to verify go version:

go version

To create your first Go project, say hello, do following commands one by one:

  • First, create a project folder named ‘hello’ and navigate into that folder.
    mkdir hello && cd hello

    Then, initialize new module (here use example/hello as module name) in current directory to create a go.mod file to manage dependency.

    go mod init example/hello

  • Now, let’s create new file, hello.go for example, with your favorite text editor:
    nano hello.go

    Then, add the first code and save it (For nano, press Ctrl+S then Ctrl+X):

    package main
    
    import "fmt"
    
    func main() {
        fmt.Println("Hello, World!")
    }

  • Finally, either use go run hello.go command to run it. Or go build hello.go to build into a binary file.

Uninstall Go

To uninstall golang, simply delete the go directory under /usr/local by running command:

sudo rm -rf /usr/local/go

That’s it.

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

4 responses to How to Install GO (golang 1.25) in Ubuntu 24.04 | 22.04

  1. Thanks : this howto helped me build an add-on for LibreELEC with Ubuntu 22.04.

    • Thanks, good post, but there is a small problem in this article.
      ‘go: go.mod file not found’


      ubuntu@first-Jellyfish:~$ go install
      go: go.mod file not found in current directory or any parent directory; see 'go help modules'
      ubuntu@first-Jellyfish:~$ cd /usr/local/bin
      ubuntu@first-Jellyfish:/usr/local/bin$ go version
      go version go1.22.5 linux/amd64
      ubuntu@first-Jellyfish:/usr/local/bin$ cd ~ && mkdir hello && cd hello
      ubuntu@first-Jellyfish:~/hello$ go mod init example/hello
      go: creating new go.mod: module example/hello
      ubuntu@first-Jellyfish:~/hello$ vi hello.go

      package main

      import "fmt"

      func main() {
      fmt.Println("Hello, World!")
      }

      ubuntu@first-Jellyfish:~/hello$ go run .
      Hello, World!
      ubuntu@first-Jellyfish:~/hello$ ls -l
      total 8
      -rw-rw-r-- 1 ubuntu ubuntu 32 Jul 30 17:15 go.mod
      -rw-rw-r-- 1 ubuntu ubuntu 74 Jul 30 17:18 hello.go

  2. However, when installing any package, let’s say “go install github.com/a-h/templ/cmd/templ@latest” the package will be installed in ~/go/bin … and it’s command “templ” will not be recognized at all since it is not part of the $PATH. This will keep most new users away.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> 

*