Ubuntu

How to Install Go on Ubuntu 20.04

Install Go on Ubuntu 20.04

Introduction

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.

Source: https://talks.golang.org/2014/gocon-tokyo.slide#28

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.

This tutorial will help you to install Go on your Ubuntu 20.04 machine.

Installing Go

Downloading 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

Modifying 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

Getting started programming with Go

We’re going to build a simple Go program for demonstration.

Firstly, create a workspace directory for Go by running:

$ mkdir ~/go

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")

}

To build the program, running the command:

$ go build

Execute the program:

./hello-world

Output:

Conclusion

You’ve already installed Go on your Ubuntu 20.04 machine. Now you can start programming Go language.

If you have any concerns, please let me know.

Similar Posts