Go is a popular programming language that is designed by Google. Professional users utilize the Go language to develop different applications. It is easy to build, simple to manage, efficient, and reliable application software. Go language syntax is entirely similar to the “C” language. However, it has more features than the “C” language, such as structural typing, garbage collection, memory safety, and more.
This blog will teach you the installation procedure of Go on Ubuntu 22.04 using three different methods:
- using apt command
- using Snap
- from Binary file
So, let’s begin!
Method 1: Go installation on Ubuntu 22.04 using apt command
“Apt” repository is a package management system in Ubuntu 22.04 that enables the user to install the newly available version of software easily. To install the “Go” on Ubuntu 22.04, follow the below steps.
Step 1: Update system packages
To update the system packages, first open the terminal by pressing “Ctrl+Alt+T” and write out the “apt update” command on the terminal:
$ sudo apt update
Step 2: Go installation on Ubuntu 22.04
Now, execute the following “apt” command for the installation of “Go” on Ubuntu 22.04 by utilizing the following:
$ sudo apt install golang-go
Step 3: Check Go version
Next, check the version of “Go” to ensure the installation. To do so, execute the “go” command with the “version” option on the terminal:
$ go version
The given output shows that we have installed Go version “go1.18.1” on our system:
How to Remove Go from Ubuntu 22.04
If you want to uninstall the Go from Ubuntu 22.04 apt repository, run the given below command:
$ sudo apt remove golang-go
Now, move to the next method to install Go on Ubuntu 22.04 by using the Snap store.
Method 2: Go installation on Ubuntu 22.04 using Snap
Snap store is a package management system that is used for discovering, installing, and managing the software. It comes pre-installed on Ubuntu 22.04. However, if it is not installed on Ubuntu 22.04 due to some reason, install it using the command:
$ sudo apt install snapd
Later, you can install “Go” easily by utilizing the Snap store on Ubuntu 22.04. Follow the given below steps.
First, open the terminal by pressing the “CTRL+ALT+T” then execute the below-given “snap”’ command as follows:
$ sudo snap install go --classic
Below output indicates that the “Go” is installed successfully on Ubuntu 22.04 with the newly available version “1.18.2”:
How to Remove Go through Snap
If you want to remove the “Go” from Ubuntu 22.04 system, type the provided “snap” command:
$ sudo snap remove go
As you can, “Go” is removed successfully from our system:
Now, move to the third method to install the “Go” on Ubuntu 22.04 from the Binary file.
Method 3: Go install from Binary file
You can also install “Go” on Ubuntu 22.04 by using Binary files. To do so, follow the below steps:
Step 1: Downloading Go Binary file
First you have to download the binary file of Go latest version by utilizing the following “wget” command:
$ wget https://golang.org/dl/go1.18.linux-amd64.tar.gz
Step 2: Extracting Go binary file
After successfully downloading the Go binary file, extract it in the “/usr/local” directory with the help of the following command:
$ sudo tar -xf go1.18.linux-amd64.tar.gz -C /usr/local
Now, use any editor that you desire to open the “Go” profile. Here, we are using the “nano” editor.
$ sudo nano /etc/profile
The nano editor will be open; place the below provided PATH at the end of the opened file:
export PATH=$PATH:/usr/local/go/bin
After adding the path, save the opened file by pressing “Ctrl+O” and exit from the editor by utilizing the “Ctrl+X” keys.
Now, execute the following command on the terminal to reload the new PATH environment:
$ source /etc/profile
As shown in the below output, now the path is changed:
Step 3: Check Go version
Check the version of installed “Go” on Ubuntu 22.04 with the following command:
$ go version
Below output shows that now we have “go1.18” installed on our system:
How to use Go on Ubuntu 22.04
To use Go on Ubuntu 22.04, follow the below-given procedure.
Step 1: Create a Project
First you need to create the project directory using the “mkdir” command and then move to the newly created directory with the help of the “cd” command:
$ mkdir -p itslinux
cd itslinux
Step 2: Set the Path
Now, set the path using mentioned below command:
$ go mod init example/itslinux
Step 3: Creating Go file in text editor
Next, open your favorite editor. Here, we are using the “nano” editor to create a file named “itslinux.go” to ensure the Go installation:
$ nano itslinux.go
Step 4: Editing Go file
Now, add the below-provided source code into the opened file and save it by pressing “CTRL+O”:
package main
import "fmt"
func main() {
fmt.Printf("Welcome To itslinux\n")
}
Step 5: Run Go file
Execute the created file with the following “go” command:
$ go run .
Execution of the above-given command will print out the message “Welcome To itslinux” on your Ubuntu terminal:
We have compiled different methods to install Go on Ubuntu 22.04.
Conclusion
Go can be installed on Ubuntu 22.04 by utilizing different methods such as using Snap store with the “$ sudo snap install go –classic” command or from the “apt” repository executing the “$ sudo apt install golang-go”, or you can also install it with downloaded Go binary files through the “$ wget https://golang.org/dl/go1.18.linux-amd64.tar.gz” command. In this blog, you have learned different methods to install Go on Ubuntu 22.04.
Saryia is a professional writer with a passion for simplifying complex topics. Specializing in Linux, programming, and technology, Saryia creates in-depth tutorials and articles designed to educate and empower readers.