Learn How To Installing Golang on Ubuntu 14.04

January 19, 2020

Table of Contents

Golang is a programming language developed by Google that would keep the traditions of C, but focus on simplicity and safety. It has become a popular language used for server-side development and networking. This tutorial is not distribution-specific. We will install Golang onto Ubuntu 14.04, but these instructions should work on CentOS or any other linux distribution (with a few minor changes if needed).

Download Golang

For 32-bit systems, run:

wget https://storage.googleapis.com/golang/go1.3.3.linux-386.tar.gz
tar -xf go1.3.3.linux-386.tar.gz

For 64-bit systems, run:

wget https://storage.googleapis.com/golang/go1.3.3.linux-amd64.tar.gz
tar -xf go1.3.3.linux-amd64.tar.gz

Move Directory

Upon extraction, you will get a directory named go. Move this folder to /opt/ (or a directory of your choice).

mv go /opt/

If you decide to put it into a different directory, remember to change the directory path accordingly in the next couple of steps.

Add to Environment Path

For everything to work like it should, you will need to do several things. Create two system variables called GOROOT and GOPATH. These two variables will be used by Golang itself when building your application. You will also need to create a directory to store any dependencies being pulled.

mkdir /opt/gopkg
export GOPATH="/opt/gopkg" 
export GOROOT="/opt/go"

If you wish for the changes to be permanent upon reboot, you will need will need to run the following commands:

echo export GOPATH=/opt/gopkg >> ~/.bashrc
echo export GOROOT=/opt/go >> ~/.bashrc
echo export PATH=$PATH:$GOROOT/bin:$GOPATH/bin >> ~/.bashrc

Now you will need to add these to your PATH variable.

export PATH=$PATH:$GOPATH/bin:$GOROOT/bin 

Verify Installation

Check installation by running the go command. When you run the command, you will see a list of options.

Create a file called test.go and populate it with the following code:

package main
import "fmt"
func main(){
        fmt.Printf("Hello worldn");

You can run this script by typing the command go run test.go. The message Hello world will be printed to your terminal.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!