Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

How to install Go Programming Language on Debian 11

Hello, friends. In this short but interesting post, you will learn how to install Go (Programming Language) on Debian 11. This is one of the most popular programming languages in the world and if you are considering using it, we can help you with the beginning.

What is Go?

Go is a programming language created by Google that aims to rival Python. It is important to note that Go is one of the most popular languages because it is fast, efficient, and flexible.

Using Go, you can make applications of all kinds because it is object-oriented and supports many connections to the internet. So, you can create applications for the desktop, for the web or for continuous integration scripts.

Go has many features, but suffice it to say that it is structured and rubbish collected to improve performance. Moreover, it’s open-source and cross-platform, so we can do many things.

Installing Go on Debian 11

We have several ways to install Go, but today we will do it using the binaries that we can download from the project’s website.

- Advertisement -

To download Go to the system, we’ll need to install wget.

sudo apt install wget

Now you can download the latest stable version of the language. At the time of writing this post, the latest version is 1.18.1.

wget https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
--2022-05-03 23:50:53--  https://go.dev/dl/go1.18.1.linux-amd64.tar.gz
Resolving go.dev (go.dev)... 2001:4860:4802:32::15, 2001:4860:4802:34::15, 2001:4860:4802:38::15, ...
Connecting to go.dev (go.dev)|2001:4860:4802:32::15|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz [following]
--2022-05-03 23:50:54--  https://dl.google.com/go/go1.18.1.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 2a00:1450:4001:800::200e, 172.217.23.110
Connecting to dl.google.com (dl.google.com)|2a00:1450:4001:800::200e|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141699677 (135M) [application/x-gzip]
Saving to: ‘go1.18.1.linux-amd64.tar.gz’

go1.18.1.linux-amd64.tar.gz               100%[=====================================================================================>] 135.13M   135MB/s    in 1.0s    

2022-05-03 23:50:55 (135 MB/s) - ‘go1.18.1.linux-amd64.tar.gz’ saved [141699677/141699677]

When the download is finished, you will need to unzip it.

- Advertisement -
tar xvf go1.18.1.linux-amd64.tar.gz

Now you have to make the root user the owner of the folder and move it to a folder in the PATH like /usr/local.

sudo chown -R root:root go
sudo mv go /usr/local

Now we have to set the language environment variables. To achieve this, edit the ~/.profile file.

sudo nano ~/.profile

Then add the following

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

Remember to add it to the end of the file and replace the path with the workspace

After saving the changes and closing the editor, you have to apply the changes

source ~/.profile

Then, you can check the Go version

go version
go version go1.18.1 linux/amd64

Test Go installation

Let’s create a test application, so we can be sure what we did.

First, create the entire directory structure of our project. In this case, I will call it example which will be in a workspace called unixcop.

mkdir -p $HOME/unixcop/src/example

Now create a test file

nano ~/unixcop/src/example/example.go

And add the following code

package main 
 import "fmt"
 func main() {
 fmt.Printf("Hello, welcome to Unixcop\n")
 }

Save the changes and close the editor.

Now compile, generate the binary and run the code from the project directory.

go build example.go
go install example.go
example

And you will see the following result.

Using Go on Debian 11
Using Go on Debian 11

Conclusion

In this post, you learned how to install Go which is a programming language that wants to be the most used and for that, it has proposed to displace Python and that is something that developers can like.

Thanks for reading.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook