6 C
Texas
angeloma
Senior Writer and partner

How to install Go Language on Debian 11 / 10?

The world of software development is a complex world. Every day new and better features emerge that force developers to broaden their knowledge. However, not all these technologies are complex to assimilate, and for this purpose, I will teach you how to install GO language on Debian 11 / 10.

Go is an open-source (BSD license) programming language that was born with the objective of allowing the creation of efficient and easily distributable applications. So, it has binaries for Windows, Mac OS and of course, for Linux.

So, in this post, I will install it and create a “Hello World” file for the test.

Download and install Go Language on Debian 11 /10

Go Language is cross-platform which makes it available for Linux. However, first you have to download the binaries from the project website. But we will use the terminal that is faster and more efficient.

- Advertisement -

First, make sure you have wget installed on your computer.

:~$ sudo apt install wget

Then proceed to download Go Language. At the time of writing this post, the latest stable version is 1.17

:~$ wget -c https://golang.org/dl/go1.17.linux-amd64.tar.gz -O go.tar.gz
1.- Download and install Go Language on Debian 11 / 10
1.- Download and install Go Language on Debian 11 / 10

Then, decompress it.

:~$ tar xvf go.tar.gz

Now you have to change the folder permissions. Besides moving it to another location like /usr/local/.

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

Then, it is necessary to make some modifications to the user’s bash profile in order to use Go. Open the configuration file and add the following:

:~$ sudo nano ~/.profile
export GOROOT=/usr/local/go    
export GOPATH=$HOME/work/
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
3.- Edit the bash profile
2.- Edit the bash profile

Save the changes (CTRL + O) and close the file (CTRL + X).

With this, Go is ready for work. You can check it by showing the version of the program.

:~$ go version
3.- Go language version
3.- Go language version

Now with a “hello world” we’ll see that everything works.

Testing the installation

As I said before, the best way to test the installation is to run a real code. For this, we will use the typical “Hello World”.

First, we’ll create the directory structure. In our Home, we will create a folder for the project called work. Inside a folder called src where the source code files will go. In it, a folder called hello and inside the file hello.go. Something like this is the directory structure. The folders work and hello can be called differently.

:~$ mkdir -p $HOME/work/src/hello

Now, create the Go file and add the following:

:~$ nano ~/work/src/hello/hello.go
package main 
 import "fmt"
 func main() {
 fmt.Printf("hello, world\n")
 }
5.- Creating a go file
5.- Creating a go file

Again, save the changes and close the file.

:~$ go build hello
:~$ go install hello
:~$ hello

So, enjoy it.

Conclusion

GO is a very popular language and every day it is more and more popular. It’s simple but very powerful, besides being open source. As you have seen, its installation is really simple.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article