Golang (also known as the “Go”) is an open-source programming language supported by Google. It has built-in concurrency and a robust standard library makes it easy to understand. Golang allows automatic management of memory, has the simple syntax of writing the scripts, has a fast compilation, and supports Concurrent/Parallel Programming.
This blog will explain the different installation methods of Golang on Debian 12. It also explains the configuration of Golang on Debian 12 and will test it by running a simple Golang script.
The outline of this post is as below:
- How to Install Golang on Debian 12?
- Method 1: Using the Default Repositories
- Method 2: Using the Golang Executable
- Method 3: Using the Snapcraft
- How to Test the Golang on Debian 12
- How to Uninstall the Golang on Debian 12
How to Install Golang on Debian 12?
Golang can be installed on Debian 12 with the below-mentioned methods:
- Using the Default Repositories
- Using the Golang Executable
- Using the Snapcraft
Method 1: Using the Default Repositories
Golang comes with the default repositories of Debian 12 and can be installed using the following steps:
Step 1: Update the Packages List
Let’s update the core libraries of Debian first:
$ sudo apt update
Step 2: Install the Golang on Debian 12
Run the apt command with its “install” option to install Golang on Debian 12:
$ sudo apt install golang -y
To verify the installation, check the version:
$ go version
The Golang has been installed from the official repository of Debian 12.
Method 2: Using the Golang Executable
Another method of installing Golang on Debian 12 is by downloading its installation method from its official website. This will ensure that the updated version of the Golang will be installed on Debian 12. Open the terminal and run the command mentioned below for the installation of the Golang after downloading its installation package.
Step 1: Create and Navigate to the New Directory
Use the mkdir command to create a new directory and then use the cd command to navigate it:
$ mkdir Golang && cd Golang
Step 2: Download the Installation Package of Golang
Now download the installation package of the Golang from its official website by running the command:
$ wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz
Step 3: Remove the Previous Installations
Ensure that all the previous installations have been removed by executing the command:
$ sudo rm -rf /usr/local/go
Step 4: Extract the Downloaded Package
Extract all the downloaded packages of the Golang with the tar command:
$ sudo tar -C /usr/local -xzf go1.21.4.linux-amd64.tar.gz
Step 5: Add /usr/local/go/bin to the PATH Variable
To install the Golang on Debian 12, add the /usr/local/go/bin to the PATH variable with the following command:
$ export PATH=$PATH:/usr/local/go/bin
Step 6: Display the Version of Golang
Finally display the installed version of the Golang on Debian 12 by running the command:
$ go version
The updated package of the Golang has been installed on Debian 12.
Method 3: Using the Snapcraft
The last installation method of the Golang is by downloading the snap from SnapCraft. First, install the snapd package manager with the apt command’s “install” option:
$ sudo apt install snapd -y
Then run the below-mentioned command for the downloading and installation of the Golang from Snapcraft:
$ sudo snap install --classic go
How to Test the Golang on Debian 12?
To test the installed Golang, run the script of the Go programming language. To do so, create and open the new text file with the nano text editor:
$ nano myGoFile.go
Now type the simple script of the Go programming language to display a message of “Welcome to Liberian Geek”:
package main
import "fmt"
func main() {
fmt.Println("Welcome to Liberian Geek!")
}
Finally, compile and run the Go programming script with the following command:
$ go run myGoFile.go
The message has been displayed successfully on the screen.
How to Uninstall the Golang on Debian 12?
To uninstall the Golang on Debian 12, use the “purge” option of the apt command. This command will remove all the configuration files of the Golang on Debian 12:
$ sudo apt purge golang -y
But this is not sufficient, locate the files of the go programming languages by the following command:
$ which go
Now run one of the following rm commands to remove, where the Go executable is placed:
$ sudo rm -rf /usr/bin/go$ sudo rm -rf /usr/local/go/bin
Finally display the version of the Golang to confirm the execution of the above command:
$ go version
Similarly to uninstall the Golang using the snapd utility:
$ sudo snap remove go
This is all about the installation of the Go or Golang on Debian 12.
Conclusion
To install Golang or Go on Debian 12, three different methods are used. Download the installation package of Go from its official website and then install it. The package Golang is also available in the official repository of Debian 12 and can be installed by running the “sudo apt install golang -y” command in the terminal. The last installation method is by using the Snapcraft package of Go.
All these methods are explained in this blog with a step-by-step guide. Also, a simple command in the Go programming language has been compiled and run to test the installation of Golang on Debian 12.