Best Steps to Install GOLANG on Ubuntu 18.04


In this tutorial, I will take you through the steps to Install Golang on Ubuntu 18.04. It was created by small team in Google which consists of Robert Griesemar, Rob Pike and Ken Thompson. GO is a strong and statically type language.

Strong type means type of a variable cannot change over time. It means if you declare a variable to hold an integer, it will always hold an integer. You cannot put any boolean or string value in it. Static type means all of the variables has to be defined at the compile time.

Why GO Language?

At the time GO was created, we had few powerful languages available at that time i.e Python, Java and C/C++. But over the time, we had certain limitations with these languages. For e.g:-
a)Python is easy to use but it is little slow.
b)Java program has becoming increasingly complex type system.
c)C/C++ also becoming complex over the time and hence compile time is getting slower.
So GO language is created by optimizing the compiler and improving the compile time. You will know more about GOLANG in next few tutorials. Let's follow the steps to install GOLANG in this tutorial.

Best Steps to Install GOLANG on Ubuntu 18.04 1

Install GOLANG On Ubuntu

Before going through the steps to install golang in your system, you need to ensure prerequisites are met.

Also Read: Networking in Docker with Best Examples

Step 1: Prerequisites

a)You must have a running Ubuntu 18.04 System.

b)You need to login as root user or user with sudo access to run below commands. You can visit How to add User into Sudoers on Ubuntu 18.04 to check the steps to add User into Sudoers.


Step 2: Update Your System

You need to update your system using sudo apt-get update command.

test@localhost:~$ sudo apt-get update
Hit:1 bionic InRelease
Hit:2 stable InRelease
Hit:3 bionic-updates InRelease
Hit:4 bionic-backports InRelease
Hit:5 bionic-security InRelease
Reading package lists... Done

Step 3: Download Golang Tar file

You can go to GOLANG Download Page and download tar file for Linux using wget command. This will download go1.13.6.linux-amd64.tar.gz in current directory.

test@localhost:~$ wget
--2020-01-20 22:39:29--
Resolving (, 2404:6800:4007:809::200e
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 120081829 (115M) [application/octet-stream]
Saving to: ‘go1.13.6.linux-amd64.tar.gz’

go1.13.6.linux-amd64.tar.gz 100%[=====================================================================================>] 114.52M 5.73MB/s in 15s

2020-01-20 22:39:45 (7.55 MB/s) - ‘go1.13.6.linux-amd64.tar.gz’ saved [120081829/120081829]

Step 4: Extract Tar File

Once golang tar file is downloaded, you need to extract the compressed file by using tar command as shown below.

test@localhost:~$ tar -xvf go1.13.6.linux-amd64.tar.gz


Step 5: Setting Up the Directory

Move extracted go/ directory to /usr/local using below command.

test@localhost:~$ sudo mv go/ /usr/local/

Now you need to create a go/ directory in /home/test which will used as Project Workspace. You can choose any name you want for creating workspaces. It really does not matter.

test@localhost:~$ cd 
test@localhost:~$ mkdir go

Set the Path at the end of ~/.profile. You need to ensure that .profile is required to be set for all those users through which you want to build and run your GO Programs.

test@localhost:~$ nano ~/.profile

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

Once profile is edited and saved. You need to load the Profile Again by using below command.

test@localhost:~$ source .profile

Step 6: Check GO Version

Once GO Path is set, you can check the GO Version by running go version command as shown below.

test@localhost:~$ go version
go version go1.13.6 linux/amd64

Step 7: Write Your First GO Program

Create another directory example under go directory. We will write our first GO Program in this directory.

test@localhost:~/go$ mkdir example

Then, write a simple hello World program in hello.go as shown below. We will use our favourite editor nano to open the file and write our code.

test@localhost:~/go/example$ nano hello.go
package main

import "fmt"

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

Step 8: Build Your GO Program

Now build your program with go build command as shown below.

test@localhost:~/go/example$ go build

If you don't receive any error after completing the build then you need to check if the executable got created or not by running ls command. You can see your executable example got created.

test@localhost:~/go/example$ ls
example hello.go

Step 9: Test Program Output

Now you can run your Program and test the output as shown below.

test@localhost:~/go/example$ ./example
hello, world

Also Read: Top 15 tools to monitor disk IO Performance with Examples

Leave a Comment