Go is a programming language that is created by Google. It’s an open-source language, its syntax is similar to C but it has some advantages over C such as concurrency processing, full support for multiple-cores CPU, garbage collection.

Go is a compiled programming language, you have to compile the source code to create an executable running file.

Almost all famous Cloud Native projects are written in Go: Kubernetes, Docker, Etcd, CoreDNS, and so on.

Go is cross-platform, it can be installed on Linux, Windows, and macOS.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu related queries.

In this context, we shall look into how to install Go on your Ubuntu 20.04 machine.

Main Features of Go Programming

Below are some of the core features of Go:

1. Statically type and compiled programming language.

2. Concurrency support and Garbage collection.

3. Strong library and toolset.

4. Multiprocessing and High-performance networking.

5. Known for readability and usability (Like Python).

How to install Go on Ubuntu ?

To start this installation process, we need to follow the steps given below.

1. Download the Go package.

At the time of this writing, the latest stable Go version is 1.15.7. You can visit the official Golang download page at https://golang.org/dl/.

To download the Go tarball, run the following command:

$ wget https://golang.org/dl/go1.15.7.linux-amd64.tar.gz
$ sudo tar xf go1.15.7.linux-amd64.tar.gz -C /usr/local

2. Modify the Path environment variable

You have to add the extracted Go directory in the previous step to the $PATH variable so that the OS can know where the Go executable binaries are located.

Using your favorite editor to insert the following line to $HOME/.profile file or /etc/profile file:

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

Then, re-load the new PATH environment variable by running:

$ source .profile

Verify that Go is successfully installed on your system:

$ go version

3. Working with Go

Here, We're going to build a simple Go program for demonstration.

i. To begin, create a workspace directory for Go by running:

$ mkdir ~/go

ii. Then, create a sub-directory src/hello-world in ~/go

$ mkdir -p ~/go/src/hello-world

In the ~/go/src/hello-world directory, let's use your favorite editor to create a Go source file named helloworld.go. Its content as below:

package main
import "fmt"
func main() {
fmt.Println("Hello, LinuxWays.net")

iii. To build the program, running the command:

$ go build

iv. Execute the program:


How to uninstall Go Language from Ubuntu?

To remove Go from the system remove the directory where the go tarball is extracted. 

In this case, go is extracted to /usr/local/go. 

Also, remove the entry from ~/.bashrc or ~/.bash_profile depending upon where you added the export path.

To implement this, run the commands given below:

$ sudo rm -rf /usr/local/go
$ sudo nano ~/.bashrc        # remove the entry from $PATH
$ source ~/.bashrc

[Need urgent assistance in fixing missing packages on Ubuntu Linux Server? We are available to help you today. ]