How To Install Go Programming Language on Ubuntu 24.04 LTS
In this tutorial, we will show you how to install Go Programming Language on Ubuntu 24.04 LTS. Go, often referred to as Golang, is a statically typed, compiled programming language designed by Google. Known for its simplicity and efficiency, Go is widely used for developing scalable and high-performance applications. With the release of Ubuntu 24.04, developers are eager to harness the power of Go on this robust operating system.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step installation of Go Programming Language on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.
Prerequisites
- A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
- An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
- An Ubuntu 24.04 system with root access or a user with sudo privileges.
Install Go Programming Language on Ubuntu 24.04′
Step 1. Updating the Package Repository.
Start by updating your system to ensure all existing packages are up-to-date. This step is crucial for maintaining system stability and security.
sudo apt update sudo apt upgrade
This command updates the package list and upgrades all installed packages to their latest versions. Keeping your system updated minimizes potential conflicts during the installation process.
Step 2. Installing Go Programming Language on Ubuntu 24.04.
To install Go, you need to download the latest version of the Go binary distribution. Visit the official Go website to find the latest release.
wget https://go.dev/dl/go1.23.0.linux-amd64.tar.gz
Replace go1.20.5.linux-amd64.tar.gz
with the version you wish to install. Ensure you verify the integrity of the downloaded file to prevent any issues.
Once downloaded, extract the tarball to the /usr/local
directory, which is the recommended location for Go installations.
sudo tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
This command extracts the contents of the tarball into the /usr/local
directory, setting up the Go environment.
Step 3. Set Up Go Environment Variables
Configuring environment variables is essential for Go to function correctly. You need to set up GOPATH
, GOROOT
, and update your PATH
.
Open the .profile
file in your home directory:
nano ~/.profile
Add the following lines at the end of the file:
export GOROOT=/usr/local/go export GOPATH=$HOME/go export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Save the file and apply the changes:
source ~/.profile
These environment variables ensure that Go binaries and libraries are accessible from any terminal session.
After setting up the environment variables, verify the installation to ensure everything is configured correctly:
go version
You should see the installed Go version, similar to:
go version go1.20.5 linux/amd64
Step 4. Create a simple Go program.
Create a new directory for your Go workspace:
mkdir -p $GOPATH/src/hello
Create a new Go file:
nano $GOPATH/src/hello/hello.go
Add the following code:
package main import "fmt" func main() { fmt.Println("Hello, idroot.us World!") }
Run the program:
go run $GOPATH/src/hello/hello.go
If you see “Hello, idroot.us World!
” printed in the terminal, your Go installation is working correctly.
Step 5. Troubleshooting Common Issues.
Despite following the steps, you may encounter issues. Here are some common problems and their solutions:
- Environment Variables Not Set: If
go version
returns an error, double-check your.profile
file to ensure the environment variables are set correctly. - Permission Denied: If you encounter permission issues, ensure you have used
sudo
where necessary. - Network Issues: If the
wget
command fails, check your internet connection or try downloading the file using a different network.
Congratulations! You have successfully installed Golang. Thanks for using this tutorial for installing Go Programming Language on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Golang website.