Golang is a programming language introduced by Google in 2009. The reason behind its development is due to frustration at Google, since developers continually had to pick a language that executed efficiently but took a long time to compile, other languages that ran inefficiently in production, but easy to program. Hence, Golang was designed for fast compilation, ease of programming and efficient execution in production.
Go can be used for many different programming projects since it is a versatile programming language. It is well suited for networking/distributed systems programs and widely used in the cloud environment since developers can do more with a strong set of tools and deployment becomes easy since only a single binary must be compiled. Furthermore, Go is easy to learn due to its small set of keywords, which also make a good choice for beginners and experienced developers.
Installing Golang on a machine running Ubuntu is a straight forward process since it only required some terminal command, a few modifications and you are good to go. In this article, we are going to demonstrate the Golang installation process and start using Go by writing a simple Go application.
Download the latest binary
Before proceeding with this process check the latest Go version on their official website (https://golang.org/dl/). At the time of writing this article, version 1.13.4 was the latest Go version.
For downloading the golang on Ubuntu we will be using
curl instead of
The following command downloads the latest stable version of Golang:
curl -O https://storage.googleapis.com/golang/go[version].linux-amd64.tar.gz
Open terminal in Ubuntu and enter the following command:
curl -O https://storage.googleapis.com/golang/go1.13.4.linux-amd64.tar.gz
After downloading the binary (.tar) you need to verify it using sha256sum. The sha256sum program is designed to verify data integrity using SHA-256.
When this cryptographic hash algorithm is used properly it can confirm both the file integrity and authenticity.
The following command verifies the .tar file using sha256sum:
After verifying the file you need to extract the tarball (https://www.computerhope.com/jargon/t/tarball.htm) by executing the following command:
tar -xvf go[version].linux-amd64.tar.gz
After extracting the tarball you need to adjust the permission and move to the
go directory which is located in
To adjust the tarball permission enter the following command in terminal:
sudo chown -R root:root ./go
Enter your password and press ‘enter’.
After adjusting the tarball permission, move to the go directory by entering the following command:
sudo mv go /usr/local
Set your path variable
In order to set the path variable, you must navigate to Home directory by enter the following command:
To view all the files/directory in the Home directory enter the following command:
ls -la (if everything went well you must see
.profile appearing in the list).
TextEditor by entering the following command:
Add the following two lines to the bottom of the file:
Test your Go installation
As you already set your variable path to
HOME -> Go navigate to the home directory by entering the following command:
Ones you are in the home directory, create the
Go directory through the following command:
If the process went well you should see your go directory in your home directory.
In this example, we are going to create a hello world Go app.
Navigate to the Home directory and create the
helloworld folder and navigate to the
helloworld directory through the following command:
mkdir -p go/src/helloworld && cd go/src/helloworld
Next, you need to create the
.go file for this sample project.
Type the following command to create the golang file:
go/src/helloworld and you must be able to see the
Open the .go file in TextEditor by entering the following command in terminal:
In this example, we just going to print ‘hello, world’ in the terminal console.
Type the following code and save the file:
For Ubuntu version 18+ users
In case you try to execute your Go code and you get the following message:
Just execute these simple commands that appear in the message:
Sudo apt install golang-go
y and press
gccgo-go by entering the following command:
sudo apt install gccgo-go
y and press
To run the program just type the following command in terminal:
go run helloworld.go