Setting up a Go environment

To setup a go environment it’s very simple; install dependency’s, download the source, compile and get started.

This guide is based on Arch Linux on a machine where I had already used an AUR build of mongodb, so things like gcc were already installed.

I have read articles from people where they have had trouble getting the system setup with the necessary tools, that’s beyond the scope of this guide, and is really distro / OS specific. There appears to be plenty of help available.

Dependencys

As I mentioned, I already had AUR a packages running in the server, but all you should need for Go, if you haven’t used an AUR packaged before is install base-devel.

N.B. If you have any trouble have a look at the AUR details on Arch’s wiki

# pacman -Syu
# pacman -S base-devel

Once you have done this you need to install mercurial and a few other packages, again most of the other packages were already installed on my system.

# pacman -S bison ed mercurial

Setup bash

You need to setup bash with some Environment vars.

To do this mod your ~/.bashrc and inc. the following :

export GOROOT=$HOME/gosource
export GOARCH=amd64
export GOOS=linux
export GOBIN=$HOME/bin
export PATH=$PATH:$GOBIN

The setting are fairly obvious, but amke sure to set $GOARCH to the correct architecture, “386” for 32bit / x86 machines, and “arm” for ARM processors etc.

Download & Build The Source

Now you have installed mercurial you can use “hg” to download the source :

# hg clone -r release https://go.googlecode.com/hg/ $GOROOT

As you can see this will download the latest sources to the folder you set $GOBIN to in your ~/.bashrc file.

N.B. It might be necessary to mkdir $GOROOT prior to downloading the source, IIRC my throw an error about the missing directory.

Now it’s time to Build the Go Sources; run the following :

# cd $GOROOT/src
# ./all.bash

It might take a few mins, but the Ng compilers appeared to be built mush faster than when I built the gccgo compiler. Although this might have been due to the fact I also built gcc.

Anyway, if all goes well you should see :

X known bugs; 0 unexpected bugs

Where the X is the count f known bugs in the Go source, this doesn’t really matter.

If you don’t see this, recheck all your settings and try again.

That’s it! You now have an environment set to start building your first Go app!

This entry was posted in Go, setup. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>