This article will guide you on installing Go on the Linux distribution Ubuntu 22.04.
How to install Go on Ubuntu 22.04
There are several methods to install Go on Ubuntu 22.04 and the details of each method are given below:
Method 1: Using Apt command
The apt package management system in Ubuntu 22.04 includes the repository of Go, thus allowing the user to install the latest version of software directly from the apt command. The following installation command will be used to install Go on Ubuntu:
To check the Go version, use the following command:
Removing Go installed from Ubuntu 22.04
To remove Go installed from the apt repository, use the following command.
Method 2: Install Go from binary file
You can use this method to install the latest version of Go on Ubuntu 22.04. For that purpose, you will need to follow the steps given below:
Step 1: First, download the latest version of the Go binary file using the following command:
You can confirm the latest version by visiting the Go download page.
The above command will install the Go compressed file in the Downloads directory of Ubuntu 22.04.
Step 2: Now, use the following command to extract the file in “/usr/local” location:
Step 3: Next, use your favorite editor to open the Go profile via the following command.
Replace the above highlighted text with the text provided below:
Save the file and execute the following command to reload the new path environment:
To check the go version installed from this method, use the following command.
Removing Go installed from binary file
To remove Go from Ubuntu 22.04, execute the following command.
Method 3: Install Go using Snap
You can also install Go using the Snap Store on Ubuntu 22.04. Snap Store is a package management system that includes the latest version of the software. To install Go from Snap Store, follow the below steps.
Step 1: Open the Ubuntu terminal and use the following installation command to install Go from the Snap Store.
Removing Go through Snap
To remove Go from the Snap Store, you can use the following command.
How to use Go in Ubuntu
Once the Go installation is completed, it’s time to execute a simple code written in the Go language to test whether the environment is working fine on Ubuntu or not.
Create a directory with the name of your choice using the following command:
Now go to the directory and run the example module using the following commands:
$ go mod init example/Welcome-Users
Create a file to store your code using the following command:
Edit the file “Welcome-Users.go” using the following command:
Then paste the following code in the file:
import "fmt"
func main() {
fmt.Printf("Welcome Linux Hint Users\n")
}
Save the above file, and then use the following command to run the code:
That’s it, now you can execute other codes using the same method on Ubuntu 22.04. For further guidance, you can read the Go Documentation.
Conclusion
Go language is the right opportunity for young developers and professionals to enjoy a good coding experience. With Go, you will be able to create multiple web applications using a secure and robust coding environment. There are several methods to install Go on Ubuntu 22.04 and it’s entirely up to your which method to pick because all will install Go within a couple of minutes.