How To Install Golang On Ubuntu 20.04 LTS

On this short tutorial, we will learn how to install Golang version 1.17.3 on Ubuntu 20.04 operating system
Introduction
Go, sometimes referred to as “Golang”, is an open-source programming language that was released by Google in 2012. Google’s intention was to create a programming language that could be learned quickly. Since its release, Go has become highly popular among developers and is used for various applications ranging from cloud or server-side applications, to artificial intelligence and robotics. This tutorial outlines how to download and install the latest version of Go (currently version 1.16.7) on an Ubuntu 20.04 server, build the famous Hello, World! application, and make your Go code into an executable binary for future use.
This tutorial requires an Ubuntu 20.04 system configured with a non-root user with sudo privileges and a firewall as described in Initial Server Setup with Ubuntu 20.04.
The Go Installation task on this article will divided with subtopics as below :
- Prerequisites
- Download Go binary file
- Install Go
- Testing Golang Installation
1. Prerequisites
This tutorial requires an Ubuntu 20.04 system configured with a non-root user with sudo privileges and a firewall as described in Initial Server Setup with Ubuntu 20.04.
2. Download Go Binary File
On this stage, we will download Golang source file by using curl command line.
Output :
We will verify the integrity of the file we’ve just downloaded, we will run the sha256sum command and pass it to the filename as an argument.
Output:
Then we will extract the tarball by using tar command line.
3. Setting Go Paths
After files are extracted, then we will set the Golang path. First, set Go’s root value, which tells Go where to look for its files. We can do this by editing the .profile
file, which contains a list of commands that the system runs every time you log in.
The configuration file is located on ~/.profile
file. We will use the vi editor to edit this file.
rapik@worker2:~$ sudo vi ~/.profile
Verify the Golang version by querying its version.
4. Testing Golang Installation
On this stage, we will test the Golang installation.
We will use the Golang reserved word and create a new file called as hello.go
.
Output :
Testing hello.go, by submitting command line :
Conclusion
On this short tutorial, we have learnt how to install Go language on Ubuntu 20.04 LTS operating system and take a simple testing.