Go 1.22 introduces enhanced range-over-integer, improved standard library packages, and performance improvements. This guide installs the official Go 1.22 toolchain on Ubuntu 24.04 LTS.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- A user with sudo privileges
Step 1 – Download Go 1.22
Download the official Go tarball from golang.org:
cd /tmp
wget https://go.dev/dl/go1.22.3.linux-amd64.tar.gz
Step 2 – Extract and Install
Remove any existing Go installation and extract:
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.22.3.linux-amd64.tar.gz
Step 3 – Configure the PATH
Add Go to your PATH:
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
source ~/.bashrc
Step 4 – Verify the Installation
Check the installed version:
go version
Step 5 – Create a Hello World Program
Create a simple Go program:
mkdir -p ~/go/src/hello && cd ~/go/src/hello
cat > main.go << 'EOF'
package main
import "fmt"
func main() {
fmt.Println("Hello from Go 1.22 on Ubuntu 24.04!")
}
EOF
go run main.go
Step 6 – Build and Run a Binary
Compile to a binary:
go build -o hello main.go
./hello
Step 7 – Manage Dependencies with Go Modules
Initialise a module in your project:
go mod init myproject
go get github.com/gin-gonic/gin
go mod tidy
Conclusion
Go 1.22 is now installed on Ubuntu 24.04 LTS. Go’s fast compilation, built-in concurrency with goroutines, and excellent standard library make it ideal for building web servers, CLIs, and cloud-native tools.