In this guide, you will learn:
How to Install Go on Debian 12
There are multiple methods to install Golang (Go) on Debian 12, including:
Let’s discuss these methods in detail.
How to Install Go on Debian 12 from the Source Repository
Installing Go on Debian 12 from the source repository is a straightforward task and can be completed within seconds using the apt install command. However, before installing Go, it is advised to update your currently installed packages in Debian repository using the following command:
Note: Updating your system repository will ensure installing the updated version of the application.
After you are done with updating, it’s time to install Go on Debian 12 using the below-given command:
Once you complete the Go installation on Debian, use the version command given below to ensure Go language is successfully installed on the system:
Note: The source repository doesn’t install the latest version of Go on Debian 12.
How to Remove Go from Debian 12 Installed Through Repository
If you have installed Go from repository method, you can remove it from the Debian system using the following command:
How to Install Go on Debian 12 from Official tar.gz Method
If you want to install the latest stable version of Go on Debian 12, you can use the official tar.gz method and perform the required configuration to complete the installation. The complete step-by-step process to install Go on Debian 12 from the official tar.gz method is provided below:
Step 1: Download the Latest Version of Go tar.gz File
First, visit the Go official website and download the latest version of tar.gz file for Linux (Debian). The latest stable version of Go at the time of writing this article is 1.21.5, which you can download on Debian from the following command:
Note: The above wget command is used for 64-bit Debian systems, you have to download the i386 Go version from the website if you are running a 32-bit Debian system.
Step 2: Extract the Content of tar.gz Source File
Now extract the content of Go tar.gz file into /usr/local location on Debian from the following command:
Note: The /usr/local is a common directory for locally-installed software on Linux systems, including Debian 12.
Step 3: Add Path Environment for Go on Debian 12
To help the system in finding the Go executable file, you must add the location of Go source directory, this can be done by first opening the bashrc file on Debian using:
Then add the following line inside the bashrc file:
Note: You can find the Go location on Debian 12 using the following command:
Step 4: Make Changes to the System
You must save the file using CTRL+X, add Y and press Enter, then use the source command followed by the bashrc file to load changes to the system:
Step 5: Check Go Version on Debian 12
To ensure Debian system uses the current Go version, you can run the below-given command:
How to Remove Go from Debian 12 Installed Through tar.gz File
If you have installed Go on Debian from the tar.gz method, you can remove it by deleting the source directory using the following command:
How to Install Go on Debian 12 from Snap Store
You can also use Snap Store to install the latest version of Go on Debian 12, this can be done by first installing Snap Daemon from the following command:
Note: The Snap Daemon will allow you to run snap commands on Debian and install applications from the Snap repository.
After you complete the Snap installation, use the following command to install Go on Debian 12 from Snap Store:
How to Remove Go on Debian 12 from Snap Store
You can remove Go on Debian installed through Snap Store using the below-given command:
How to Use Go on Debian 12
To find out whether Go is working on Debian 12, let’s learn how to use it. Here, first, you must create a file with .go extension from the following command:
Note: Add a file name in place of file_name in the above command to create a file of your choice.
Inside this file, you can add your Go language code. To make things simple, I am adding a simple Go code that prints the Hello message on the terminal:
import "fmt"
func main() {
fmt.Printf("Hello Linux Hint Users\n")
}
The package main line in the above code declares a package that is necessary for running Go code, while import fmt is used to provide functions for formatted I/O. The main function body includes a line for printing the desired message on the terminal. You must save the file after adding your Go code.
To run the code, you have to use the go run command followed by the filename that you have created earlier.
This is how you can install and use Go on your Debian system.
Conclusion
Go is a robust programming language used for web development, cloud computing, data science and more. You can install Go on Debian 12 directly from the source repository, using tar.gz file or from Snap Store. The process involving source repository is simple and can be completed with a single apt command. For using tar.gz file, you have to download and extract tar.gz file in the /usr/local directory, then add the location of Go inside the bashrc file. The Snap Store method is simple and only requires installing Snap Daemon on the system and then using the snap install command to install Go. After completing the Go installation from any method, you can use it to develop scalable applications on your Debian system.