Skip to main content

How to Install Go on Debian

Go, also known as Golang, is an open-source programming language developed by Google. It is designed to be efficient, simple, and easy to use, making it a popular choice among developers for building scalable and reliable applications.

In this tutorial, we will guide you through the step-by-step process of installing Go on Debian. We will cover the installation of Go using the official tarball distribution, which provides the latest stable release.

Prerequisites

Before proceeding with the installation, ensure that you have the following prerequisites in place:

  • A Debian-based system (e.g., Debian, Ubuntu)
  • Access to a terminal with administrative privileges

Step 1: Download the Go Binary

To install Go on Debian, we need to download the official Go binary from the official website. Here are the steps to do so:

  1. Open your web browser and go to the Go Downloads page: https://golang.org/dl/
  2. Scroll down the page to find the latest stable release of Go.
  3. Choose the appropriate binary package based on your system architecture. For example, if you have a 64-bit Debian system, select the package with the filename ending in linux-amd64.tar.gz.
  4. Right-click on the download link and select "Copy link address" to copy the URL of the binary package.

Step 2: Install Go

Now that we have the Go binary package downloaded, we can proceed with the installation process. Follow the steps below to install Go on your Debian system:

  1. Open a terminal on your Debian system.
  2. Change to the directory where you want to install Go. For example, if you prefer to install it in your home directory, run the following command to navigate to your home directory:
   cd ~
  1. Use the wget command to download the Go binary package by pasting the copied URL from Step 1. For example:
   wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz

Note: Make sure to replace the URL in the above command with the one you copied in Step 1.

  1. Extract the downloaded tarball using the tar command:
   tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz

This command will extract the Go files into the /usr/local/go directory.

  1. Add the Go binary directory to the system's PATH environment variable by appending the following line to the /etc/profile file:
   export PATH=$PATH:/usr/local/go/bin

Save the file and exit the text editor.

  1. To apply the changes made to the /etc/profile file, execute the following command:
   source /etc/profile

Step 3: Verify the Installation

After completing the installation, it's essential to verify that Go has been installed correctly. Follow the steps below to verify the installation:

  1. Open a new terminal window or tab.
  2. Run the following command to check the installed Go version:
   go version

You should see the output similar to the following:

   go version go1.17 linux/amd64

This output confirms that Go has been successfully installed on your Debian system.

Step 4: Set Up Your Development Environment (Optional)

To enhance your Go development experience, you can set up your workspace and configure the GOPATH environment variable. Although it is not necessary for basic usage, it is recommended for managing your projects effectively.

  1. Create the directory structure for your Go workspace by running the following command:
   mkdir -p ~/go/{bin,src,pkg}

This command will create the necessary directories: bin, src, and pkg in your home directory.

  1. Set the GOPATH environment variable to point to your Go workspace by adding the following line to the ~/.bashrc file:
   export GOPATH=$HOME/go

Save the file and exit the text editor.

  1. To apply the changes made to the ~/.bashrc file, execute the following command:
   source ~/.bashrc

Congratulations! You have successfully installed Go on your Debian system. You are now ready to start building your Go applications.

Conclusion

In this tutorial, you learned how to install Go on Debian by downloading the official binary package and configuring the necessary environment variables. You also verified the installation by checking the installed Go version. Now you can explore the powerful features of Go and embark on your journey as a Go developer.

Remember to refer to the official Go documentation and community resources for further learning and usage examples. Happy coding with Go!