Installing Google Go
Environment variables
The Go compilation environment depends on three environment variables that you should set in your .bashrc or equivalent, plus one optional variable:
-
$GOROOT - The root of the Go tree. Typically this is
$HOME/gobut it can be any directory. -
$GOOSand$GOARCH - The name of the target operating system and compilation architecture. Choices for
$GOOSarelinux,freebsd,darwin(Mac OS X 10.5 or 10.6), andnacl(Native Client, an incomplete port). Choices for$GOARCHareamd64(64-bit x86, the most mature port),386(32-bit x86), andarm(32-bit ARM, an incomplete port). The valid combinations of$GOOSand$GOARCHare:$GOOS$GOARCHdarwin386darwinamd64freebsd386freebsdamd64linux386linuxamd64linuxarmnacl386 -
$GOBIN(optional) - The location where binaries will be installed. The default is
$HOME/bin. After installing, you will want to arrange to add this directory to your$PATH, so you can use the tools. -
$GOARM(optional, arm, default=6) - The ARM architecture version the runtime libraries should target. ARMv6 cores have more efficient synchronization primitives. Setting
$GOARMto 5 will compile the runtime libraries using just SWP instructions that work on older architectures as well. Running v6 code on an older core will cause an illegal instruction trap.
Note that $GOARCH and $GOOS identify the target environment, not the environment you are running on. In effect, you are always cross-compiling.
Set these variables in your .bashrc. For example:
export GOROOT=$HOME/go export GOARCH=amd64 export GOOS=linux
Double-check them by listing your environment.
$ env | grep '^GO'
I had to download mercurial-1.4.3 and the latest Python to get working.
Make sure the $GOROOT directory does not exist or is empty. Then check out the repository:
$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT
To build the Go distribution, run
$ cd $GOROOT/src $ ./all.bash
If all goes well, it will finish by printing
--- cd ../test N known bugs; 0 unexpected bugs
N was a happy 0 on my intraback pc.
Keeping up with releases
New releases are announced on the Go Nuts mailing list. To update an existing tree to the latest release, you can run:
$ cd $GOROOT/src $ hg pull $ hg update release $ ./all.bash
