How to Install Go on Ubuntu 24.04: Step-by-Step

The Google team developed the statically typed compiled programming language known as Go or Golang. Go is popular among developers who need to create scalable applications because of its efficient coding structure and robust programming model, which suits cloud-based programs and distributed system development. This guide provides all the necessary steps to install Go on Ubuntu 24.04 for those who wish to start their Go development journey.
#Why Go on Ubuntu?
The platform provided by Ubuntu ensures stability and reliability for developers working in the environment. The combined strength of Go's cross-platform capabilities and Ubuntu makes a powerful combination for creating diverse applications. Through the apt package management system, Ubuntu provides easy software installation alongside a large community base for user assistance when needed.
#Prerequisites:
- An Ubuntu 24.04 system with sudo privileges.
- A stable internet connection.
- Basic familiarity with the command line.
Deploy and scale your projects with Cherry Servers' cost-effective dedicated or virtual servers. Enjoy seamless scaling, pay-as-you-go pricing, and 24/7 expert support—all within a hassle-free cloud environment.
#Installing Go on Ubuntu 24.04
Go installation for Ubuntu 24.04 can be achieved through multiple pathways. This guide will focus on the official Go distribution method since it offers the most reliable and current version.
#Method 1: Installing Go from the official distribution
This method ensures you get the latest stable Go release directly from the official Go website.
#Step 1: Download the Go archive
Open a terminal and press Ctrl + Alt + T or search for *Terminal in the applications menu. Navigate to your home directory:
cd ~
Download the latest Go archive. Visit the official [Go downloads page] (https://go.dev/dl/) and identify the latest stable version for Linux (usually a .tar.gz file). Replace version with the actual version number in the following command:
For instance, the current latest version is 1.24.2, the command would be:
wget https://go.dev/dl/go1.24.2.linux-amd64.tar.gz
Output--2025-04-01 22:26:30-- https://go.dev/dl/go1.24.2.linux-amd64.tar.gz
Resolving go.dev (go.dev)... 216.239.36.21, 216.239.38.21, 216.239.34.21, ...
Connecting to go.dev (go.dev)|216.239.36.21|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.24.2.linux-amd64.tar.gz [following]
--2025-04-01 22:26:30-- https://dl.google.com/go/go1.24.2.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 142.250.196.174, 2404:6800:4007:809::200e
Connecting to dl.google.com (dl.google.com)|142.250.196.174|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 74762151 (71M) [application/x-gzip]
Saving to: ‘go1.24.2.linux-amd64.tar.gz’
go1.24.2.linux-ar 100%[=============>] 71.30M 23.1MB/s in 3.1s
2025-04-01 22:26:34 (23.1 MB/s) - ‘go1.24.2.linux-amd64.tar.gz’ saved [74762151/74762151]
#Step 2: Extract the archive
Save the downloaded archive in the /usr/local
directory, the standard software installation location.
sudo tar -C /usr/local -xzf go1.24.2.linux-amd64.tar.gz
ls -l /usr/local/go*
Outputtotal 72
drwxr-xr-x 2 root root 4096 Mar 27 00:39 api
drwxr-xr-x 2 root root 4096 Mar 27 00:39 bin
-rw-r--r-- 1 root root 52 Mar 27 00:39 codereview.cfg
-rw-r--r-- 1 root root 1337 Mar 27 00:39 CONTRIBUTING.md
drwxr-xr-x 3 root root 4096 Mar 27 00:39 doc
-rw-r--r-- 1 root root 505 Mar 27 00:39 go.env
drwxr-xr-x 5 root root 4096 Mar 27 00:39 lib
-rw-r--r-- 1 root root 1453 Mar 27 00:39 LICENSE
drwxr-xr-x 8 root root 4096 Mar 27 00:39 misc
-rw-r--r-- 1 root root 1303 Mar 27 00:39 PATENTS
drwxr-xr-x 4 root root 4096 Mar 27 00:39 pkg
-rw-r--r-- 1 root root 1454 Mar 27 00:39 README.md
-rw-r--r-- 1 root root 426 Mar 27 00:39 SECURITY.md
drwxr-xr-x 56 root root 4096 Mar 27 00:39 src
drwxr-xr-x 28 root root 12288 Mar 27 00:39 test
-rw-r--r-- 1 root root 35 Mar 27 00:39 VERSION
#Step 3: Configure environment variables
The ~/.profile
file requires editing because it enables login-dependent environment variable configuration.
sudo nano ~/.profile
The following lines must be appended at the end of the file because they both add the Go binary directory path to the PATH variable while also establishing the GOPATH
and GOROOT
variables.
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
- GOROOT: Specifies the root directory of the Go installation.
- GOPATH: The workspace directory for Go projects and dependencies should be specified here.
- PATH: Adds the Go binary directory to your system's executable path.
Save the file and exit. The changes become active by either performing a new login or executing the below command to source the ~/.profile
file:
source ~/.profile
#Step 4: Verify the installation
Check the Go version:
go version
This command should display the installed Go version.
Outputgo version go1.24.2 linux/amd64
Check the Go environment:
go env
This command will display the Go environment variables, including GOROOT
and GOPATH
.
OutputAR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='x64'
GOAMD64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/ubuntu/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/ubuntu/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1563029445=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/home/ubuntu/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/ubuntu/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/ubuntu/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.2'
GOWORK=''
PKG_CONFIG='pkg-config'
#Method 2: Using apt (Less recommended)
Ubuntu's repositories might contain an older Go version. While this method is simpler, it might not provide the latest features and security updates.
Firstly, update the package list:
sudo apt update
Install Go using apt:
sudo apt install golang-go
OutputReading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu g++ g++-13
g++-13-x86-64-linux-gnu g++-x86-64-linux-gnu gcc gcc-13 gcc-13-x86-64-linux-gnu
gcc-x86-64-linux-gnu golang-1.22-go golang-1.22-src golang-src libasan8
libbinutils libcc1-0 libctf-nobfd0 libctf0 libgcc-13-dev libgprofng0 libhwasan0
libitm1 liblsan0 libpkgconf3 libquadmath0 libsframe1 libstdc++-13-dev libtsan2
libubsan1 pkg-config pkgconf pkgconf-bin
Suggested packages:
binutils-doc gprofng-gui g++-multilib g++-13-multilib gcc-13-doc gcc-multilib
make autoconf automake libtool flex bison gcc-doc gcc-13-multilib gcc-13-locales
gdb-x86-64-linux-gnu bzr | brz git mercurial subversion libstdc++-13-doc
The following NEW packages will be installed:
binutils binutils-common binutils-x86-64-linux-gnu g++ g++-13
g++-13-x86-64-linux-gnu g++-x86-64-linux-gnu gcc gcc-13 gcc-13-x86-64-linux-gnu
gcc-x86-64-linux-gnu golang-1.22-go golang-1.22-src golang-go golang-src libasan8
libbinutils libcc1-0 libctf-nobfd0 libctf0 libgcc-13-dev libgprofng0 libhwasan0
libitm1 liblsan0 libpkgconf3 libquadmath0 libsframe1 libstdc++-13-dev libtsan2
libubsan1 pkg-config pkgconf pkgconf-bin
0 upgraded, 34 newly installed, 0 to remove and 0 not upgraded.
Need to get 45.7 MB/100 MB of archives.
After this operation, 431 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Ign:1 http://archive.ubuntu.com/ubuntu noble-updates/main amd64 golang-1.22-src all 1.22.2-2ubuntu0.2
Get:3 http://archive.ubuntu.com/ubuntu noble/main amd64 golang-src all 2:1.22~2build1 [5078 B]
Get:4 http://archive.ubuntu.com/ubuntu noble/main amd64 golang-go amd64 2:1.22~2build1 [43.9 kB]
Get:5 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 binutils-common amd64 2.42-4ubuntu2 [239 kB]
Get:6 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libsframe1 amd64 2.42-4ubuntu2 [14.8 kB]
Get:7 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libbinutils amd64 2.42-4ubuntu2 [572 kB]
Get:8 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libctf-nobfd0 amd64 2.42-4ubuntu2 [97.1 kB]
Get:9 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libctf0 amd64 2.42-4ubuntu2 [94.5 kB]
Get:10 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libgprofng0 amd64 2.42-4ubuntu2 [851 kB]
Get:11 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 binutils-x86-64-linux-gnu amd64 2.42-4ubuntu2 [2469 kB]
Get:12 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 binutils amd64 2.42-4ubuntu2 [18.0 kB]
Get:13 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libcc1-0 amd64 14-20240412-0ubuntu1 [47.7 kB]
Get:14 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libitm1 amd64 14-20240412-0ubuntu1 [28.9 kB]
Get:15 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libasan8 amd64 14-20240412-0ubuntu1 [3024 kB]
Get:16 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 liblsan0 amd64 14-20240412-0ubuntu1 [1313 kB]
Get:17 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libtsan2 amd64 14-20240412-0ubuntu1 [2736 kB]
Get:18 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libubsan1 amd64 14-20240412-0ubuntu1 [1175 kB]
Get:19 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libhwasan0 amd64 14-20240412-0ubuntu1 [1632 kB]
Get:20 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libquadmath0 amd64 14-20240412-0ubuntu1 [153 kB]
Get:21 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libgcc-13-dev amd64 13.2.0-23ubuntu4 [2688 kB]
Get:22 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 gcc-13-x86-64-linux-gnu amd64 13.2.0-23ubuntu4 [21.9 MB]
Get:23 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 gcc-13 amd64 13.2.0-23ubuntu4 [482 kB]
Get:24 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 gcc-x86-64-linux-gnu amd64 4:13.2.0-7ubuntu1 [1212 B]
Get:25 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 gcc amd64 4:13.2.0-7ubuntu1 [5018 B]
Get:26 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libstdc++-13-dev amd64 13.2.0-23ubuntu4 [2399 kB]
Get:27 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 g++-13-x86-64-linux-gnu amd64 13.2.0-23ubuntu4 [12.5 MB]
Get:28 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 g++-13 amd64 13.2.0-23ubuntu4 [14.5 kB]
Get:29 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 g++-x86-64-linux-gnu amd64 4:13.2.0-7ubuntu1 [964 B]
Get:30 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 g++ amd64 4:13.2.0-7ubuntu1 [1100 B]
Get:31 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 libpkgconf3 amd64 1.8.1-2build1 [30.7 kB]
Get:32 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 pkgconf-bin amd64 1.8.1-2build1 [20.7 kB]
Get:33 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 pkgconf amd64 1.8.1-2build1 [16.8 kB]
Get:34 cdrom://Ubuntu 24.04.1 LTS _Noble Numbat_ - Release amd64 (20240827.1) noble/main amd64 pkg-config amd64 1.8.1-2build1 [7264 B]
Fetched 49.0 kB in 3s (15.4 kB/s)
Selecting previously unselected package golang-1.22-src.
(Reading database ... 212379 files and directories currently installed.)
Preparing to unpack .../golang-1.22-src_1.22.2-2ubuntu0.3_all.deb ...
Unpacking golang-1.22-src (1.22.2-2ubuntu0.3) ...
Selecting previously unselected package golang-1.22-go.
Preparing to unpack .../golang-1.22-go_1.22.2-2ubuntu0.3_amd64.deb ...
Unpacking golang-1.22-go (1.22.2-2ubuntu0.3) ...
Setting up golang-1.22-src (1.22.2-2ubuntu0.3) ...
Setting up golang-src (2:1.22~2build1) ...
Setting up golang-1.22-go (1.22.2-2ubuntu0.3) ...
Setting up golang-go:amd64 (2:1.22~2build1) …
Verify the installation:
go version
Outputgo version go1.22.2 linux/amd64
Note: If you install Go using apt
, you might need to manually configure the GOPATH
and PATH
variables as described in Method 1.
#Writing your first Go program
Let’s run a simple Go program. Create a new directory for your project:
mkdir -p ~/go/src/hello
cd ~/go/src/hello
Create a file named hello.go
:
nano hello.go
Add the following code to hello.go:
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
Save the file and exit. Run the program using the command below:
go run hello.go
OutputHello, Go!
This will output "Hello, Go!" to the terminal.
#Building and installing the program
You can also build and run an executable file of the program. To build the program, run the command below:
go build hello.go
ls
This will create an executable file named hello in the current directory.
./hello
This will give the below output:
OutputHello, Go!
You can also compile and install a Go package to your system's $GOPATH/bin
directory, making the compiled binary available system-wide. To install the program, run the command below:
go install hello.go
This will install the executable to the $GOPATH/bin
directory, making it available from anywhere in your system.
Run the installed program:
hello
This will give the below output:
OutputHello, Go!
You have successfully installed Go on Ubuntu 24.04!
#Conclusion
Installing Go on the Ubuntu 24.04 system requires simple steps to perform. The steps presented in this guide enable quick setup of your Go development environment so you can begin developing robust applications. Using the official distribution provides you with the current features and security updates. Setting up your Go development environment requires the correct configuration of environment variables, especially GOPATH and PATH, to streamline your Go development workflow. Your Ubuntu 24.04 system can now start producing remarkable applications after installing and setting up Go. Happy coding!
Cloud VPS Hosting
Starting at just $3.24 / month, get virtual servers with top-tier performance.