Installing Golang on Ubuntu 14.04

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 world\n");
}

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

  • Installing Golang on Ubuntu 14.04
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Setup Ragnarok Online Server on Ubuntu 14.04 x64

In this article, we are going to setup a Ragnarok Online Server on Ubuntu 14.04 x64. You can be...

Installing Ubuntu Server on Drives Larger Than 2 TB

The following tutorial requires a motherboard that is EFI compatible (most boards since 2012 are...

Enabling root user in Ubuntu

Instructions on how to enable root user in a newly installed Ubuntu server. The root user in...

Install MailCatcher On Ubuntu 14

Introduction MailCatcher is a tool that provides an easy way for developers to inspect emails...

Install PostgreSQL On Ubuntu 14

Introduction PostgreSQL is the world's most advanced open source Relational Database Management...