Installing Go on Ubuntu

When Google announced their newly developed system programming language Go, I decided to give it a try on my Ubuntu machine, the Mac would have to wait. The installation was supposed to be a walk in the park, but it wasn’t. I realized I didn’t have some other essential tools installed, and encountered one problem after another, frantically googling for solutions. So in this post I’ll detail the step by step process to install and run Go on your Ubuntu machine.

Step 1: Setting Up Environment Variables

Prior to installation you need to have these environment variables set up:

$GOROOT – The root of the Go tree. Typically this is $HOME/go but it can be any directory.

$GOOS – Name of the target operating system. Since this is Ubuntu the value would be ‘linux’

$GOARCH – Name of the target compilation architecture.  If you’re on a 32 bit x86 machine this would be ‘386’. Check out this section in Go online docs for other options.

$GOBIN – The location where binaries will be installed. You can set this to $HOME/bin or whatever path of your choice. Then you have to add this to your $PATH so that newly built Go-specific command such as the compiler can be found during the build.

Fire up the terminal and type the following command

sudo vi /etc/profile

This’ll open up the system-wide bash profile file in vi editor. You need to add the following lines at the end of the file.

export GOROOT=$HOME/go
export GOOS=linux
export GOARCH=386
export GOBIN=$HOME/bin

Now add $GOBIN to your $PATH. Open .bashrc in your $HOME directory

sudo vi $HOME/.bashrc

and add the line

export PATH=${PATH}:$GOBIN

Restart the machine for these changes to take effect.
Reload the files for the changes to take effect(thanks peter vahlu)

source /etc/profile
source ~/.bashrc

Step 2: Install Mercurial and clone Go repository

Google uses Mercurial to store Go source code, so you have to install it and fetch the repository.

Since 1.0, Mercurial has been installable by easy-install. So you need to get the python setuptools, header files and other essential  tools installed  first.

sudo apt-get install python-setuptools python-dev build-essential

Now install Mecurial

sudo easy_install -U mercurial

This part was quite confusing. Mercurial was throwing up some errors when I tried to clone Go’s repo.

*** failed to import extension hgext.hbisect: No module named hbisect

The extension bisect is a built-in command since version 1.0 and so should not be used. If you get this error, open the configuration file(/etc/mercurial/hgrc.d/hgext) and remove/comment out the line hbisect=

Make sure the $GOROOT directory does not exist or is empty. Then check out the repository:

hg clone -r release $GOROOT

Step 3: Build Go from source

The Go tool chain is written in C. To build it, you need to have GCC, the standard C libraries, the parser generator Bison, make and the text editor ed installed.

sudo apt-get install bison gcc libc6-dev ed make

Next, build Go from source

cd $GOROOT/src


If all.bash runs without trouble, it’ll finish by printing

--- cd ../test

N known bugs; 0 unexpected bugs

Where N is the number of bugs, changes from release to release.

You now have GO installed on your Ubuntu. Happy coding!

Further Reading

  1. The installation page at Go website.
  2. Article on installing Mercurial on Ubuntu and dealing with its tantrums.

Accessing Linux file system from Windows

In a dual-boot system(one which has both Windows and Linux installed), Linux is smart enough to provide you access to Windows VFAT/NTFS partitions. But same is not the case for Windows.

Ext2 IFS is a free software(not open source) that allows you to do that. It installs a pure kernel mode file system driver Ext2fs.sys, which actually extends the Windows operating system to include the Ext2 file system. You can download it from The linux file system will appear as a new disk partition in windows.

If you install this software, I would recommend you to make the linux the drive read-only. Windows is susceptible to Virus/Worm/Trojan attacks. I didn’t want malicious files to spread in my Ubuntu partition.