Go, also known as Golang, is a popular open-source programming language developed by Google. It’s known for its simplicity, efficiency, and strong support for concurrent programming. In this guide, we will walk you through the steps to install Go on a Debian Linux system.

Advertisement

Prerequisites

  • A Debian-based Linux system
  • Access to a terminal
  • Basic knowledge of Linux commands

Step 1: Update Your System

Before installing any new software, it’s a good practice to update your system. Open your terminal and run the following commands:

sudo apt update 
sudo apt upgrade 

This process will ensure that all your system’s packages are up-to-date.

Step 2: Downloading Golang

Visit the official Go website to find the latest version of Golang. You can download it directly using the wget command. Replace the URL in the command below with the latest download link:

wget https://go.dev/dl/go1.21.linux-amd64.tar.gz 

Step 3: Extracting the Go Archive

After downloading, extract the archive to the /usr/local directory. This is the standard directory for user-installed software.

sudo tar -xvf go1.21.linux-amd64.tar.gz -C /usr/local 

Step 4: Setting Up Go Paths

For Go to function properly, you need to set up the GOROOT and GOPATH environment variables. GOROOT is the location where Go is installed, and GOPATH is the workspace for Go projects.

Add these lines to your ~/.profile or ~/.bashrc file:


export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH

After adding these lines, apply the changes with:

source ~/.profile 

or

source ~/.bashrc 

Step 5: Verifying the Installation

To ensure Go is installed correctly, you can run:

go version 

This command will display the installed version of Go.

Step 6: Creating Your First Go Project

Now that Go is installed, you can start your first project. Create a new directory for your project in the Go workspace:

mkdir $GOPATH/src/hello 
cd $GOPATH/src/hello 

Create a file named hello.go and add a simple Hello World program:


package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

Run your program with:

go run hello.go 

You should see “Hello, World!” printed in the terminal.

Conclusion

Congratulations! You have successfully installed Golang on your Debian Linux system and created your first Go program. Go is a powerful language with a rich ecosystem, and you’re now ready to explore more complex Go projects and contribute to the Go community.

Remember to check the Go documentation and join Go forums and communities for further learning and support. Happy coding!

Share.

5 Comments

  1. I agree with Christian.
    And in the same time i get 2 questions :
    1/ why don’t you install the “official” debian package.
    In my distro the last version is 1.14 why do you want to get the 1.15 one?
    Debian packages get pre and post scripts that do the job for you.

    2/ Such a strange way to do by copying files that way! No?
    Not surprised that you complain of strange behavior afterwards.

  2. do NOT copy everything to /usr/local like I did “go/* /usr/local ”

    I’ve been trying to clean up this mess for a few hours now.

    Honestly, why is this installation a mess to begin with?
    Some kind of bash installation script would help a lot of noobs out here.

Leave A Reply


Exit mobile version