16 C
Texas
angeloma
Senior Writer and partner

How to install GO language on Ubuntu 20.04 / 18.04?

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

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.

1. Install GO Language

The installation of GO is quite simple, just download the binaries and move them to the preferred location. Of course, you can also check that the installation is correct through the key.

- Advertisement -

So, install wget package.

:~$ sudo apt install wget

Then, download GO binaries.

:~$ wget -c https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
--2020-06-08 23:47:29--  https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
Resolving dl.google.com (dl.google.com)... 142.250.64.206, 2607:f8b0:4008:80c::200e
Connecting to dl.google.com (dl.google.com)|142.250.64.206|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 123711003 (118M) [application/octet-stream]
Saving to: ‘go1.14.4.linux-amd64.tar.gz’
go1.14.4.linux-amd64.tar.gz                100%[=====================================================================================>] 117,98M   162KB/s    in 17m 45s 
2020-06-09 00:05:17 (113 KB/s) - ‘go1.14.4.linux-amd64.tar.gz’ saved [123711003/123711003]

1.- Download and install GO
1.- Download and install GO

Note: At the time of writing this post the latest stable version of GO is 1.14.4.

Now, it is necessary to decompress the file.

:~$ tar xvf go1.14.4.linux-amd64.tar.gz

Next, Next, change the owner of the folder and move it to /usr/local/.

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

Many people prefer to change the route to another, but the recommended one is /usr/local/.

2. Working with the paths

Now you need to make some adjustments to your GO routes. For example, set Go’s root value, which tells Go where to look for its files.

:~$ sudo nano ~/.profile

At the end of the file add the following:

export GOROOT=$HOME/go
export GOPATH=$HOME/work
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

Note: These parameters work if GO was installed in the personal folder. If this is not the case, you must specify the paths.

In this case:

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

Setting the paths
2.- Setting the paths

Now, for the changes to take effect, it is necessary to refresh your bash profile.

:~$ source ~/.profile

Check the GO version installed.

:~$ go version
go version go1.14.4 linux/amd64

Checking the GO version
3.- Checking the GO version

3. Creating a Hello World file

Now to check that everything is OK, you need to create a GO file and run it.

First, create the GO workspace. Don’t worry, it is a folder. I will call it work. Look at the above image.

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

Then, create the first GO file.

:~$ nano ~/work/src/hello/hello.go

Now, add these lines.

package main 
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}

3.- Creating the hello world file
4.- Creating the hello world file

Now, compile the file, install the package generated, and then run it.

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

Go working on Ubuntu 20.04 / Ubuntu 18.04
Go working on Ubuntu 20.04 / Ubuntu 18.04

And that’s 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.

Please share this article on your social networks. Also, join our Telegram Channel and buy us a coffee.

You can also read “How to install pgAdmin4 on Ubuntu 20.04“.

- 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