Linux

How to Install Go on Ubuntu 20.04

How to Install Go on Ubuntu 20.04

Go, often referred to as golang is a modern open-source programming language created by Google that allows you to build reliable and efficient applications. Go is a compiled language, which means you need to compile the source code to create an executable file that is used to run the software.

Many popular applications, such as Kubernetes, Docker, Prometheus, and Terraform, are written in Go.

This tutorial explains how to download and install Go on Ubuntu 20.04.

Installing Go on Ubuntu 20.04

Complete the following steps to install Go on Ubuntu 20.04:

1. Download the Go tarball

At the time of writing this article, the latest stable version of Go is version 1.14.2. Before downloading tarball, visit the official Go page download and check if there is a new version available.

Run the following command as a user with sudo rights to download and extract the binary Go archive in the / usr / local directory:

wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local

2. Adjusting the Path Variable

By adding the location of the Go directory to the $ PATH environment variable, the system will know where to find executable Go binaries.

This can be done by adding the following line to the / etc / profile file (for system-wide installation) or $ HOME /. Profile file (for current user installation):

~/.profile
export PATH=$PATH:/usr/local/go/bin

Save the file, and load the new PATH environment variable into the current shell session:

source ~/.profile

3. Verify the Go Installation

Verify the installation by printing the Go version:

go version

The output will look like this:

Output :

go version go1.14.2 linux/amd64

Get started with Go #

To test Go installation, we will create a workspace and build a simple program that prints the classic “hello world” message.

1. By default, the GOPATH variable, which determines the workspace location is set to $ HOME / go. To create a workspace directory type:

mkdir ~/go

2. In the workspace create a new directory src / hello:

mkdir -p ~/go/src/hello

and in that directory create a file called hello.go:

~/go/src/hello/hello.go
package main

import "fmt"

func main() {
    fmt.Printf("Hello, World\n")
}

To learn more about the Go workspace directory hierarchy, visit the Go Documentation page.

3. Navigate ** to the ~ / go / src / hello directory and run go build to build the program:

cd ~/go/src/hellogo build

The above command will create an executable file named hello.

4. You can run the executable only by running the command below:

./hello

The output will look like this:

Output :

Hello, World

Conclusion

Now that you have downloaded and installed Go on your Ubuntu system, you can start developing your Go project.

If you experience problems or get feedback, leave a comment below.

Related posts

How to Activate Dark Mode on Ubuntu 20.04 LTS

Howto

How to install Chef Server and Chef Client on Ubuntu 20.04

Linux

Tutorial mktemp Linux Commands for Beginners (5 Examples)

Howto

How to Add Elements to a List in Python (add, add and enter)

Linux

How to properly secure sysctl on Linux

Linux

How to Grep Way for Various Strings and Patterns

Linux

How to install Zulip chat server on Ubuntu 18.04

Linux

How to Make a Minecraft Server on Ubuntu 20.04

Linux

How to Install Eclipse IDE on Ubuntu 20.04

Linux