In this post I’ll be going over how to setup Google’s Go in Ubuntu 12.04 64bit version. If you follow these steps you’ll have the build tools for Go installed which can compile for 386 or amd64 systems.

First you’ll need to install Subversion, Git and Mercurial which Go uses to download packages. In addition you’ll need some basic C build tools installed which will be used to compile Go itself. From the command line run the following:

sudo apt-get install mercurial git subversion gcc libc6-dev libc6-dev-i386

Next make sure you’re logged in as your normal user account. Add the below to your .bashrc file:

#This line will tell the Go installer where to place the source code before compilation
export GOROOT=$HOME/go

#With this line, you choose the architecture of your machine.
#Those with 64 bit CPUs should enter "amd64" here.
export GOARCH=amd64

#Your operating system
export GOOS=linux

#And now the location where the installer will place the finished files
#Don't forget to create this directory before installing
export GOBIN=$GOROOT/bin

#Include Go binaries in command path

When you do the above either run “source ~/.bashrc” to load the new settings or close and re-open a new terminal window.

Now you can install Go itself:

cd ~
hg clone -u release

cd go/src/

cd ~

This should install the basic Go build tools. Test this by putting the below code into a hello.go file:

package main

import "fmt"

func main() {
fmt.Printf("hello, world\n")

And then compile and run it:

go build hello.go


The above will have created a 64bit binary. But we can also setup Go to be able to compile i386 binaries:

cd ~/go/src/
GOARCH=386 ./all.bash

Once that’s done, go back and re-compile hello as an i386 binary:

cd ~
GOARCH=386 go build hello.go

Note that this binary will still run on your 64bit Ubuntu system since you have 32bit compatibility libraries installed on your system.