Saturday, 14 November 2009

Google Go! on Mac OS-X

Google have just released a new programming language called Go.

I decided to install it and learn it.

This is what I did on Leopard 10.5.8. It took 5 easy steps (thanks to Kelvin Wong).

Step 1.

I installed mercurial (the Google instructions to use easy_install did not work for me)

Step 2.

I added these lines to ~/.profile (Kevin added his to ~/.bash_profile)

To determine what file to edit or create requires you to follow a procedure because bash only reads in the first one it finds:

If you have a ~/.bash_profile file, edit it.
Else if you have a ~/.bash_login file, edit it.
Else if you have a ~/.profile file, edit it.
Else if you have a ~/.bashrc file, edit it.
Else you may create one of the above.

I already had a ~/.profile file since I use fink and it creates one. Others have used ~/.bash_profile or ~/.bashrc.
export GOROOT=$HOME/go
export GOARCH=386
export GOOS=darwin
export GOBIN=$HOME/bin
I then closed and re-opened the terminal session.

I checked that it worked with
env | grep '^GO'
Step 3.

I manually created ~/bin and followed Kelvin's recommendation to make it executable with
mkdir ~/bin
chmod 755 ~/bin
Step 4.

I downloaded the Go repository using mercurial.
hg clone -r release $GOROOT
This printed the following:
requesting all changes
adding changesets
adding manifests
adding file changes
added 4016 changesets with 16888 changes to 2931 files
updating working directory
1640 files updated, 0 files merged, 0 files removed, 0 files unresolved
Step 5.

I built the Go compiler.
cd $GOROOT/src
During this step, OS-X asked me to allow in incoming connection to an application called 8g.

This didn't seem to work as I got this error:
FAIL: http.TestClient
Get dial tcp lookup on 10.x.x.x:53: no answer from server
This group discussion on the error suggests that Go is actually built but that the Go DNS resolver may not work on OS-X just yet.

It will work if 'Allow all incoming connections' is selected in the Firewall section of the Security preferences.