Go is a powerful and efficient programming language that has gained popularity as “the language of the cloud.” Developed by Google, Go offers a quick compiler, easy programming, and efficient production, making it a preferred choice for networking and distributed systems programs. In this tutorial, we will guide you through the process of installing and configuring Go on your Debian 11 system.
Prerequisites
Before getting started, make sure you have the following prerequisites:
- A server with Debian 11 installed.
- A non-root user with sudo privileges.
Updating the System
To begin, let’s update the packages on your Debian 11 system. Open your terminal and run the following command:
sudo apt update && sudo apt upgrade -y sudo apt install wget software-properties-common apt-transport-https
This will ensure that your system is up to date and install any necessary packages for the installation process.
Installing Go on Debian 11
Now, let’s proceed with installing Go on your Debian 11 system. The latest release of Go can be downloaded from the official Go downloads page. At the time of writing, version 1.17 is the latest release. You can download it using the following command:
cdwget https://golang.org/dl/go1.17.linux-amd64.tar.gz
After the download is complete, extract the downloaded file and place it in the recommended directory, /usr/local
. You can do this by running the following command:
sudo tar -zxvf go1.17.linux-amd64.tar.gz -C /usr/local/
With Go successfully installed, let’s move on to setting up the Go environment.
Setting up the Go Environment
In this step, we will configure the Go environment variables. These variables are essential for Go to function properly. To set up the environment, follow these steps:
- Open your terminal and enter the following command to create the
go.sh
file:
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee /etc/profile.d/go.sh
- Next, source the
go.sh
file by running the following command:
source /etc/profile.d/go.sh
- To ensure that the environment variables persist, add the same command to your
~/.profile
file:
echo "export PATH=/usr/local/go/bin:${PATH}" | sudo tee -a $HOME/.profile
- Source your
~/.profile
file:
source $HOME/.profile
To verify that the Go environment has been set up correctly, run the following commands in your terminal:
go version go env
These commands will display the installed Go version and the Go environment variables, confirming that Go has been successfully installed on your Debian 11 system.
Creating a Testing Project
Now that you have Go installed and the environment set up, let’s create a simple testing project to ensure everything is working as expected. In this example, we will create a “Hello World” program.
- Open your favorite text editor and create a new file called
helloworld.go
:
sudo nano helloworld.go
- Populate the file with the following code:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
- Save the file and exit the text editor.
- Run the following command to execute the program:
go run helloworld.go
If everything is set up correctly, you should see the output Hello, World!
in your terminal.
Congratulations! You have successfully installed Go on your Debian 11 system and tested it with a simple program.
Conclusion
In this tutorial, we have walked you through the process of installing and configuring the Go programming language on Debian 11. Go is a powerful language with a growing community and a wide range of applications, especially in the cloud environment.
To learn more about Go and explore its features, visit the official Go website. If you have any questions or run into any issues, feel free to leave a comment below.
Remember to check out Shape.host for reliable and secure Linux SSD VPS hosting services. Shape.host offers scalable solutions to empower your business with efficient cloud hosting.