How to Install Go on Ubuntu 20.04?

install go on ubuntu 20.04 3

Golang, majorly known as Go, 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 also written in Go.

Also Read: How to Install NginX on Ubuntu 20.04?

In this tutorial you’ll learn to download and install Go on Ubuntu 20.04 server.

#1 Installing Go on Ubuntu 20.04

In order to install Go on your Ubuntu 20.04 server, the following steps will get you there:

Step 1: Download the Go tarball

When I wrote this article, the latest stable version of Go is version 1.14.2. Before downloading the tarball, please do visit the official Go downloads page and check if there is a new version available.

Run the following command as a user with sudo privileges to download and extract the Go binary 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

Step 2: Adjusting the Path Variable

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

This can be done easily by using the following command-line either to the /etc/profile file (for a system-wide installation) or the $HOME/.profile file (for a 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

Step 3: Verifying the Go Installation

Verify the installation by printing the Go version:

go version

The output should look something like this:

go version go1.14.2 linux/amd64

#2 Getting Started with Go

To verify the Go installation, you can create a workspace and build a simple program that prints the all-time favorite “hello world!” message.

  1. By default, the GOPATH variable, which specifies the location of the workspace is set to $HOME/go. To create the workspace directory type: mkdir ~/go
  2. Inside the workspace create a new directory src/hello: mkdir -p ~/go/src/hello and in that directory create a file named hello.go: ~/go/src/hello/hello.go package main import "fmt" func main() { fmt.Printf("Hello, Worldn") } To learn more about 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 command above will build an executable file named hello.
  4. You can run the executable by simply executing the command below: ./hello The output should look something like this: Hello, World

#3 Conclusion

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

If you hit a problem don’t hesitate in leaving a comment below.

Scroll to Top
0 Shares
Tweet
Share
Share
Pin