Installing Golang on an Ubuntu Server

Posted: January 06, 2012

Here's a very quick set of commands to run on a fresh Ubuntu server. I did this today to verify that my new golang orm, gorp installs cleanly in a fresh Go environment.

Step 1 - Install Dependencies

# Install the required packages (plus git, for github hosted projects)
sudo apt-get update
sudo apt-get install bison gawk gcc libc6-dev make mercurial git

Step 2 - Download and build Go

# I like to chown /usr/local to a non-root user, 
# but that's personal preference
cd /usr/local
sudo chown -R ubuntu:ubuntu .
    
# Clone the Go repo.  Change 'weekly' to 'release' if you want
# the last stable release.
hg clone -u weekly https://go.googlecode.com/hg/ go
cd go/src
    
# This builds and installs Go
./all.bash

Step 3 - Setup environment variables

# You might want to add these to your ~/.profile
export PATH=$PATH:/usr/local/go/bin
export GOROOT=/usr/local/go

Step 4 - Install a package with goinstall

goinstall has the convenient ability to install packages directly from github/bitbucket/launchpad repos. For example, to install gorp:

# install package
# note: goinstall will be replaced in Go 1.0 with the general "go" command
goinstall github.com/coopernurse/gorp

# verify you have it by looking at the docs
godoc github.com/coopernurse/gorp | less

That's it. Pretty easy.