How to Install Go on Ubuntu 18.04

r00t June 13, 2018

Install Go on Ubuntu 18.04

In this tutorial we are going to learn how to install Go on Ubuntu 18.04. We will also install and configure its prerequisites. Go also understand as Golang, is an open source programming language developed by Google. Many popular programs, including Grafana, Docker and Kubernetes, are written in Go.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 18.04 Bionic Beaver minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Go on Ubuntu 18.04

Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:

apt-get update -y
apt-get upgrade -y

Step 2. Installing Go on Ubuntu 18.04.

First, download the Go binary you can use either wget or curl:

wget https://dl.google.com/go/go1.10.3.linux-amd64.tar.gz

Next, use tar to extract the tarball to the /usr/local directory:

sudo tar -C /usr/local -xzf go1.10.3.linux-amd64.tar.gz

Then add it to your path:

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

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

source ~/profile

As the final test, if we run this:

go version

Step 3. Sample Go Application.

We will make our sample application something systems related. This sample application will be a simple app to show you the system time:

nano gettime.go

Put in the following contents:

package main

import (
        "fmt"
        "time"
)

func main() {
        fmt.Println(time.Now())
}

Go is a compiled language so we need to compile our code to a native executable:

go build gettime.go

Then, will now have an executable in your current directory that you can run:

$ ./gettime
2018-06-12 20:46:16.774145422 +0000 UTC m=+0.000132589

Congratulation’s! You have successfully install and configured Go on your Ubuntu 18.04 server. Thanks for using this tutorial installing Go open source programming language on Ubuntu 18.04 LTS (Bionic Beaver) system.

The Tags:

Leave a Comment

Comments are closed.