How to Install Go on Ubuntu 24.04?
Go (Golang) is an open-source and powerful programming language that’s known for its efficiency and strong support for concurrency. It addresses the need for reliable execution, efficient compilation, and ease of programming. It’s particularly well-suited for building cloud or server-side applications, command-line tools, and other distributed services.
Installing Go can significantly streamline the development process on Ubuntu 24.04, which is known for its stability and wide support. This combination allows developers to create robust applications that can scale efficiently and maintain high performance.
This tutorial will demonstrate the step-by-step procedure for installing Go in Ubuntu.
How to Install Go on Ubuntu 24.04
The process of installing Go on Ubuntu is straightforward. There are various methods for installing Go on Ubuntu 24.04, but we’ll focus on two primary ones as below:
Let’s start with the easy one.
Method 1: Install Go on Ubuntu 24.04 Using the APT Package Manager
Installation of Go makes it accessible for developers of all skill levels to set up their programming environment and start coding with minimal setup time. To install Go on Ubuntu 24.04, follow the below steps:
Step 1: Update Package Index
Before you begin, make sure that the Ubuntu system is up-to-date. Let’s, update the package index on the Ubuntu system:
sudo apt update
Step 2: Install Go
Now, install Go using the apt package manager. It installs Go from the default repositories, which may not be the recent version:
sudo apt install golang-go
Step 3: Verify Go Installation
Now, check the installed version of Go with the “go version” command to confirm the installation. Let’s check the installed version of Go:
go version
Optional: Uninstall Go
To uninstall Go (Golang) from an Ubuntu system, users can utilize the package manager with commands. It removes all Go-related packages:
sudo apt remove golang-go sudo apt purge golang-go sudo apt autoremove golang-go
If you’ve manually installed Go that is typically found in “/usr/local/go”. They might need to remove the Go directory using the “rm” command:
sudo rm -rf /usr/local/go
That is all from the default package manager.
Method 2: Installing Go from the Official Binary Distribution
Installing Go on Ubuntu 24.04 can be a straightforward process. If users require the latest version, download the recent binary file. To install Go latest version from the official binary distribution, follow these steps:
Step 1: Remove Previous Installations
First, users should remove any previous installations of Go by deleting the “/usr/local/go” directory, if it exists. They do this with the below command:
sudo rm -rf /usr/local/go
Step 2: Download the Go Binary
Visit the official Go website and download the latest binary release suitable for your system. Alternatively, download the Go tarball from the official Go website. For instance, download the latest version which is currently 1.22.1:
wget https://go.dev/dl/go1.22.1.linux-amd64.tar.gz
Step 3: Extract the Archive
Once downloaded, extract the tarball into “/usr/local” to create a new Go tree in “/usr/local/go” using the command. Let’s extract the go1.22.1 downloaded file:
sudo tar -C /usr/local -xzf go1.22.1.linux-amd64.tar.gz
Note: Replace “go1.22.1.linux-amd64.tar.gz” with the version for downloading files.
Step 4: Set Up the Environment Variables
After extracting Go, users need to add “/usr/local/go/bin” to the PATH variable. This can be done by adding the line “export PATH=$PATH:/usr/local/go/bin” to your “$HOME/.profile” or “/etc/profile”:
nano ~/.bash_profile
Add the Go binary to your PATH by adding the following line to your “$HOME/.profile” or “/etc/profile”:
export PATH=$PATH:/usr/local/go/bin
Step 5: Apply the Changes
Remember to apply the changes by running “source $HOME/.profile” or logging out and back in:
source $HOME/.profile source ~/.bash_profile
Step 6: Verify Installation
Finally, verify the installation by typing “go version” in the terminal. This displays the installed version of Go:
go version
With Go installed on your Ubuntu 24.04 system, you’re now ready to start coding and building efficient applications.
Optional: Post-Installation Steps
After installing Go, setting up your workspace is a good approach. Go uses a specific directory structure called a workspace, which contains three directories at its root:
– “src”: The directory where your Go source files (.go) reside.
– “pkg”: The directory where the package objects are stored.
– “bin”: The directory where the compiled executables are stored.
How to Run a Golang Program on Ubuntu 24.04?
Running a Golang program on Ubuntu 24.04 involves a series of steps starting from the installation of Go, setting up the environment, and finally executing the program. Let’s run Golang program:
Step 1: Install GO
Firstly, make sure that Go is installed on the Ubuntu system; users can also install it via the package manager or by downloading the package from the official Go website:
sudo apt install golang-go
Step 2: Set up Workspace (Optional)
Next, set up your workspace by creating a directory for your Go projects and setting the GOPATH variable to point to your workspace. You can do this by adding “export GOPATH=$HOME/work” and “export PATH=$PATH:/usr/local/go/bin” to the “~/.profile” or “~/.bashrc” file.
Step 3: Write Go Code
After setting up the environment, write the Go code in a file with a “.go” extension using a text editor:
sudo nano linuxgenie.go
package main
import "fmt"
func main() {
fmt.Println("Linuxgenie educates the Linux User")
}
Step 4: Build Program (Optional)
To build the program, navigate to the project directory in the terminal and execute “go build”. It compiles the code and generates an executable:
go build
Step 5: Run Executable
Finally, replace the program with the actual name of your program. For instance, our program name is “linuxgenie” as below:
go run linuxgenie.go
Note: Users can also run the executable by writing “./program” in the Linux terminal. For detailed instructions and different methods of installation, users can refer to various online resources.
Conclusion
Go offers a robust platform for developing modern software. To Install Go on Ubuntu 24.04, update packages and install GO using the “sudo apt install go” command. You can set up your workspace by defining the “GOPATH” environment variable, which points to the location of your workspace.
To install the GO latest version, remove the older version of Go installed, download the Go tarball from the official Go website, extract the downloaded archive using tar, and set up your workspace. Finally, confirm the installation by checking the Go version.
To write and run Go code in Ubuntu, you’ll need to install Go, set up your development environment, and use the “go” command to build and execute your programs.









