Golang is a high-level programming language developed by the Google team and was announced in 2009.
Go is inspired by different programming languages, however, the Go development team aims to produce a simple and efficient programming language for its users.
Go (Golang) has some awesome key features, such as it is an open-source programming language and contains a robust standard library.
This tutorial will go through the different installation methods of Golang on Debian 12.
What are the Golang Installation Methods for Debian 12?
Golang can be installed on Debian 12 by one of the below methods:
- Using the Snapcraft Package
- Using the Default repository
- Downloading the Golang from its Official Website
Method 1: Install Golang on Debian 12 Using the Snapcraft Package
Snapcraft is known as the Linux application store that contains a hundred Linux snaps. For managing these snaps including downloading, installing, updating, and removing them, snapd package manager can be used.
Use the below-mentioned steps for installing Go using the Snapcraft package.
Step 1: Install the Package Manager for Snapcraft
First install the snap package manager for managing the Linux application Snaps:
$ sudo apt install snapd -y
Step 2: Download and Install the Golang Snap
To download and install the snap of Go, run the command:
$ sudo snap install go --classic
The snap of Golang (Go) programming language has been successfully installed.
What is the Method on Debian 12 to Remove the Golang?
To remove the Go on Debian 12 using the snapd package manager, execute the command:
$ sudo snap remove go
Method 2: Install Golang on Debian 12 Using the Default Repository
The Golang package comes in the default repository of Debian 12 and can be installed following the next-mentioned steps.
Step 1: Update the Debian Packages
Update all the Debian packages:
$ sudo apt update
Step 2: Find the Golang Package
To find the package details of “Golang” including the version, use the command:
$ sudo apt show golang
Step 3: Install Golang on Debian 12
Now install the package Golang from the default repository, and use the apt package manager:
$ sudo apt install golang -y
Step 4: Verify the Golang’s Installation
For the verification, display the installed version of the Golang:
$ go version
How to Remove and Uninstall Golang on Debian 12?
To remove and uninstall the Golang with all its associated packages, use the apt manager’s purge option:
$ sudo apt purge golang -y
Method 3: Install Golang on Debian 12 by Downloading from its Official Website
The last installation method of Golang is by downloading from its official website. To use this method, first, download the “tar” package of Golang and then install it after extracting.
Step 1: Download the tar Package of Golang
To download Golang’s tar package, run the command:
$ wget https://go.dev/dl/go1.20.7.linux-amd64.tar.gz
Step 2: Extract the Golang’s tar Package
After downloading the tar package of “Golang” on Debian 12, extract it and also copy all its contents in /usr/local/ directory:
$ sudo tar -xf go1.20.7.linux-amd64.tar.gz -C /usr/local
Step 3: Define the Environmental Variable
To use the Golang, define the environmental variable “$PATH” by opening the /etc/profile using the nano text editor:
$ sudo nano /etc/profile
In the /etc/profile/ file, paste the below-mentioned line:
$ export PATH=$PATH:/usr/local/go/bin
Save the file with the shortcut CTRL+S and exit the nano text editor.
Step 4: Reload the profile
To apply the changes, reload the profile:
$ source .profile
Close and then relaunch the terminal. Display the version of the Golang using:
$ go version
How to Test the Golang Installation on Debian 12?
To test the installation of the Golang on Debian 12, create a file with the “go” extension. For example, create a file with the name “MyGoCode.go” using the nano text editor:
$ nano MyGoCode.go
Write the below-mentioned Go script for printing a message:
package main
import "fmt"
func main() {
fmt.Printf("Welcome to ItsLinuxFoss\n")
}
Save the file with the CTRL+S and then use the “go” command to execute the go script:
$ go run MyGoCode.go
The output has been displayed on the screen successfully.
These all are the installation methods of Golang on Debian 12.
Conclusion
To install Golang on Debian 12, the easiest method is to use the default repository package with the “sudo apt install golang -y”. Other installation methods include the Snapcraft package and by downloading from its official website of the Golang programming language. This post has explanations for each of the listed installation methods. Moreover, the usage of the Go programming script has been demonstrated.