Step-by-Step Guide to Install Go on Debian

Ana Rivera

Updated on:

If you’re looking for how to install Go on Debian, this guide will walk you through the process step by step. By following these instructions debian go install you will ensure that you have the correct version of Go installed for your system architecture and that your Go environment is configured correctly.
If you’re wondering **how to install Go on Debian**, this guide provides detailed steps to help you get started. With clear instructions and commands, you’ll have Go up and running on your Debian system in no time.

Install Go on Debian

Step 1: Update Your System

First, make sure your system is up-to-date. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade -y

Step 2: Check Your System’s Architecture

It’s important to download the correct version of Go for your system. To check your system’s architecture, run:

uname -m
  • If the output is x86_64, you have a 64-bit x86 system.
  • If the output is armv7l, you have a 32-bit ARM system.
  • If the output is aarch64, you have a 64-bit ARM system.

Step 3: Download the Correct Go Binary

Based on your system’s architecture, download the appropriate Go binary from the official Go download page. Here are the commands for different architectures:

For 64-bit x86 (x86_64):

wget https://golang.org/dl/go1.17.3.linux-amd64.tar.gz 

For 32-bit ARM (armv7l):

wget https://golang.org/dl/go1.17.3.linux-armv6l.tar.gz

For 64-bit ARM (aarch64):

wget https://golang.org/dl/go1.17.3.linux-arm64.tar.gz

If the above versions are outdated, visit the official Go download page to get the latest version and update the download link accordingly.

Step 4: Remove Any Previous Go Installation

If you have previously installed Go, you should remove it to avoid conflicts. Run:

sudo rm -rf /usr/local/go

Step 5: Extract the Downloaded Archive

Extract the Go tarball to the /usr/local directory. Adjust the filename based on the file you downloaded:

sudo tar -C /usr/local -xzf go1.17.3.linux-amd64.tar.gz  # Replace with the correct file if different

Step 6: Set Up Go Environment

Add the Go binary to your PATH environment variable. You can do this by editing your ~/.profile file. Open ~/.profile in a text editor:

nano ~/.profile

Add the following line at the end of the file:

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

Save the file and exit the editor (in nano, press CTRL+X, then Y, and Enter).

To apply the changes, run:

source ~/.profile

Step 7: Verify the Installation

Verify that Go is installed correctly by checking its version. Run:

go version

You should see the installed version of Go, for example:

go version go1.17.3 linux/amd64

Step 8: Create a Go Workspace

It’s good practice to create a workspace for your Go projects. By default, Go expects a workspace directory structure like this:

~/go
   ├── bin
   ├── pkg
   └── src 

Create this structure and set the GOPATH environment variable:

mkdir -p ~/go/{bin,pkg,src}
echo "export GOPATH=$HOME/go" >> ~/.profile
source ~/.profile

FAQ

How do I install Go on Debian?

To install Go on Debian, update your package list, download the Go tarball, extract it to /usr/local, and add Go to your PATH. Use commands: sudo apt update, download the tarball, sudo tar -C /usr/local -xzf go1.x.x.linux-amd64.tar.gz, and add export PATH=$PATH:/usr/local/go/bin to ~/.profile.

How can I install Go on Linux?

To install Go on Linux, visit the official Go website, download the appropriate Linux binary package, and use the wget command to fetch it. Extract the downloaded file using tar and move it to /usr/local. Finally, add Go to your PATH by updating your profile file and source it.

How do I install programs on Debian?

To install programs on Debian, use the APT package management tool. Open a terminal and run sudo apt update to update the package list, then sudo apt install [package_name] to install the desired software from the official repositories. This ensures safety and compatibility.

What is the Go install command?

The Go install command compiles the specified packages and installs the resulting binaries in your workspace’s bin directory. This makes it easy to run Go applications from the command line.FAQ

Conclusion

You have now installed Go on your Debian system and set up your workspace. You can start writing and running Go programs. If you encounter any issues, double-check that you downloaded the correct binary for your system’s architecture and that your environment variables are set correctly.