Go, also known as Golang, is a modern and popular open-source programming language created by Google. It has gained popularity for its simplicity, performance, and extensive community support. Many well-known software applications, including Grafana, Docker, and Kubernetes, are developed using Go. In this tutorial, we will walk you through the process of setting up the Go language environment on your Debian 10 Linux system, from downloading to installation.

Prerequisites

Before you begin the installation process, ensure that your system is running Debian 10 Linux and that you have user access with sudo privileges to execute administrative commands.

Installing Go on Debian 10 Linux

The installation and configuration of the Go language on Debian Linux are straightforward. You can download and install Go with just a few simple steps.

Step 1 – Downloading the Go Tarball Package

Start by downloading the latest Go tarball package. Visit the official Go download page to check for the most recent version. You can use either the curl or wget command to download the tarball. Here’s an example using wget:

$ wget https://dl.google.com/go/go1.15.2.linux-amd64.tar.gz

Step 2 – Verifying the Go Tarball Package

To ensure the integrity of the downloaded tarball, use the sha256sum command to verify it. Compare the hash you get with the one listed on the download page. It should match.

$ sha256sum go1.15.2.linux-amd64.tar.gz

Step 3 – Extracting the Go Package

Use the tar command to extract the tarball package to the /usr/local directory.

$ sudo tar -C /usr/local -xzf go1.15.2.linux-amd64.tar.gz

Step 4 – Configuring the Path Variable

To make Go executable binaries accessible system-wide, you need to adjust the $PATH environment variable. Append the following line to the /etc/profile file:

export PATH=$PATH:/usr/local/go/bin

After saving the file, load the new PATH environment variable into the current shell session:

$ source ~/.profile

Step 5 – Verifying the Go Installation

Verify the successful installation of the Go programming language by checking the version:

$ go version

You should see output similar to this:

go version go1.15.2 linux/amd64

Getting Started with Go

Now that you have Go installed on your Debian 10 system, let’s set up a basic Go workspace and create a simple “Hello, World!” program.

Step 1 – Creating a Go Workspace

By default, Go creates a workspace directory in the user’s home directory, under $HOME/go. Create the workspace with this command:

$ mkdir ~/go

Step 2 – Creating a Program Directory

Inside the workspace, create a directory for your program. For example, let’s create a directory called program1:

$ mkdir -p ~/go/src/program1

Step 3 – Writing a Go Program

Inside the program1 directory, create a file named hello.go and add the following Go program:

package main
import “fmt”
func main() {    fmt.Printf(“Hello, World!\n”)}

Step 4 – Building and Running the Program

Navigate to the program1 directory and build the Go application:

$ cd ~/go/src/program1$ go build

This command will build an executable file named program1. You can run your program with:

$ ./program1

You will see the output:

Hello, World!

Comparison Table 

Comparison of Go Installation Methods on Debian 10:

MethodEase of InstallationAdvanced FeaturesControl Over VersionsProsCons
Download and Install from Official WebsiteModerateLimitedYes– Provides the latest Go version directly from the official website.– Requires manual installation and PATH configuration.
Use apt Package ManagerEasyLimitedLimited– Simple installation using standard package management.– May not offer the latest Go version.
Use Snap PackageEasyLimitedLimited– Quick and easy installation via Snap.– May not have the latest Go version.

This table provides a clear comparison of the various methods for installing Go on Debian 10, highlighting their ease of installation, advanced features, control over versions, and the pros and cons associated with each method. It can help readers make an informed choice based on their requirements.

Man working on a laptop with a phone

 

Video Guide 

In order to finally answer all your questions, we have prepared a special video for you. Enjoy watching it!

Conclusion

Congratulations! You’ve successfully installed the Go language on Debian 10 Linux and created your first Go program. Go’s simplicity, performance, and versatility make it a great choice for various programming tasks. You’re now ready to explore more of what this powerful language has to offer. Happy coding!

FAQ

1. What is Go (Golang), and why should I use it on Debian 10?

Go, also known as Golang, is a popular open-source programming language created by Google. It’s known for its simplicity, efficiency, and strong support for concurrency. Installing Go on Debian 10 allows you to develop and run Go applications seamlessly on your Debian-based system.

2. Can I install Go on other Debian versions besides Debian 10?

Yes, you can install Go on various Debian versions. However, the installation steps might slightly differ based on the version. The steps outlined in this guide are specific to Debian 10, but you can adapt them for other Debian versions as needed.

3. What if I need to switch between different versions of Go?

Go provides a straightforward way to manage multiple versions using the “Go Version Manager” or “gvm.” You can install gvm separately and use it to switch between Go versions on your Debian 10 system.

4. Is there a graphical IDE available for Go development on Debian 10?

Yes, there are several popular integrated development environments (IDEs) available for Go, such as Visual Studio Code with the Go extension, GoLand by JetBrains, and LiteIDE. You can install these IDEs on Debian 10 to enhance your Go development experience.