Google released a new programming language named GO that offers the benefits of a dynamic language like Python with the speed of a compiled language like C/C++. In this walkthrough, I’m going to be installing the Google Go programming language on my Mac.
To get started, make sure that you have Python and Mercurial installed on your Intel Mac (PowerPC is not supported at this point). Also make sure that you have XCode installed and that you are attached to the Internet (the test suite will need Internet access to run a few tests).
Trinity:~ kelvin$ python -V
Python 2.5.2
Trinity:~ kelvin$ hg version
Mercurial Distributed SCM (version 1.0.1)
Copyright (C) 2005-2008 Matt Mackall <mpm@selenic.com> and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Trinity:~ kelvin$ xcodebuild -version
Xcode 3.1.2
Component versions: DevToolsCore-1148.0; DevToolsSupport-1102.0
BuildVersion: 9M2621
Trinity:~ kelvin$ uname -p
i386
Trinity:~ kelvin$
Okay, now we’re going to make some environment variables that Go will use to compile your code. In my home directory, I put the following variables into the ‘.bash_profile’ file:
# Google Go Lang Vars
export GOROOT=$HOME/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
export PATH=$GOBIN:$PATH
Now we make sure that the environment has the variables we just set up:
Trinity:~ kelvin$ source .bash_profile
Trinity:~ kelvin$ env | grep ^GO
GOBIN=/Users/kelvin/bin
GOARCH=386
GOROOT=/Users/kelvin/go
GOOS=darwin
Trinity:~ kelvin$
Make sure that your ‘~/go’ directory doesn’t exist since the next command will make it into a Mercurial repository. We will be creating the ‘~/bin’ directory after we create the repository.
Trinity:~ kelvin$ hg clone -r release https://go.googlecode.com/hg/ $GOROOT
requesting all changes
adding changesets
adding manifests
adding file changes
added 3976 changesets with 16799 changes to 2931 files
updating working directory
1640 files updated, 0 files merged, 0 files removed, 0 files unresolved
Trinity:~ kelvin$ cd $GOROOT
Trinity:go kelvin$ ls
AUTHORS LICENSE doc include misc src
CONTRIBUTORS README favicon.ico lib pkg test
Trinity:go kelvin$ cd src/
Trinity:src kelvin$
Okay, so far we have set-up the environment and the respository. Now would be a good time to ensure the ‘~/bin’ folder actually exists. In many cases, it is already there. If it isn’t there, you need to create it and mark it executable (Hint: Try ‘mkdir ~/bin’ then ‘chmod 755 ~/bin’).
Trinity:src kelvin$ test -e ~/bin && echo 'bin exists'
bin exists
Trinity:src kelvin$
Okay, now we’re ready to build Go.
Trinity:src kelvin$ ./all.bash
rm -f *.o *.6 6.out lib9.a
rm -f bbuffered.o bfildes.o bflush.o bgetc.o bgetrune.o bgetd.o binit.o boffset.o bprint.o bputc.o bputrune.o brdline.o brdstr.o bread.o bseek.o bwrite.o *.6 6.out libbio.a
rm -f *.o *.so
.... holy crap there is a lot of output here...
./mkasmh.sh >386/asm.h.x
mv -f 386/asm.h.x 386/asm.h
8a 386/asm.s
8c -Idarwin -Idarwin/386 -wF cgocall.c
8c -Idarwin -Idarwin/386 -wF chan.c
8c -Idarwin -Idarwin/386 -wF 386/closure.c
8c -Idarwin -Idarwin/386 -wF float.c
8c -Idarwin -Idarwin/386 -wF hashmap.c
8c -Idarwin -Idarwin/386 -wF iface.c
quietgcc -o cgo2c cgo2c.c
./cgo2c malloc.cgo > malloc.c.tmp
mv -f malloc.c.tmp malloc.c
...Two peanuts were walking down the street. One was a salted...
8g -I_obj main.go
8l -L_obj -o ogle main.8
real 0m0.996s
user 0m0.831s
sys 0m0.148s
--- cd ../doc/progs
real 0m2.229s
user 0m1.714s
sys 0m0.431s
--- cd ../test/bench
fasta
reverse-complement
nbody
binary-tree
binary-tree-freelist
fannkuch
regex-dna
spectral-norm
k-nucleotide
mandelbrot
meteor-contest
pidigits
threadring
chameneosredux
--- cd ../test
0 known bugs; 0 unexpected bugs
Trinity:src kelvin$
Okay, so hopefully you now have a working copy of the Go programming language. You can try to find the executables on your system. Your compiler is ’8g’ if for the i386 architecture.
Trinity:~ kelvin$ which 8g
/Users/kelvin/bin/8g
Trinity:~ kelvin$ which 8l
/Users/kelvin/bin/8l
Trinity:~ kelvin$ 8g
flags:
-I DIR search for packages in DIR
-d print declarations
-e no limit on number of errors printed
-f print stack frame structure
-h panic on an error
-k name specify package name
-o file specify output file
-S print the assembly language
-w print the parse tree after typing
-x print lex tokens
Trinity:~ kelvin$
Notice that ‘gccgo’ is not installed by default; if you want to try that out you need to install it separately. Try working through the examples!
#1 by Nicolas on November 12, 2009 - 1:09 pm
Hi Wongo,
big thanks for this really understandable guidiance.
Thanks a lot!
Greets,
Nicolas
#2 by Christian BRUNEL on November 12, 2009 - 4:48 pm
Hi Kelvin,
Thank you for this information.
You helped me install Go language on my iMac running Snow Leopard. It runs well in a terminal, but how do you integrate it with XCode ? Might be obvious for skilled XCode developers, but I am a basic XCode user.
Thanks in advance.
Christian
#3 by eric on November 12, 2009 - 7:58 pm
Thanks for the writeup! I’ve got a similar setup, but compilation blows up during “making libmach” with the line:
$GOROOT/src/libmach/darwin.c:439: error: syntax error before âx86_thread_state32_tâ
It’s all errors from there on out.
Any hints on this one? The grumbles on the interwebs are true: googling for issues related to “google go” produces more or less random results.
My system:
$ uname -a
Darwin localhost 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh
Thanks!
E
#4 by kelvin.wong on November 13, 2009 - 3:59 am
@Christian: I haven’t tried this in Xcode yet. You might be able to get some help by posting your note to the Google Group for the Go language.
@Eric: You are running this on a PowerPC Mac? If so, Google Go does not yet support the PPC arch. There are already some posts to the Google Group on this subject.
#5 by eric on November 13, 2009 - 5:14 pm
Aha! Sure enough. Thanks for the pointer.
#6 by Dillon on November 14, 2009 - 12:31 pm
Hey Wongo,
I followed your instructions verbatim and when I typed
./all.bashI got this error.
$GOROOT is not set correctly or not exportedGOROOT is set to $HOME/go just how you have it. Please help, thank you.
#7 by kelvin.wong on November 14, 2009 - 4:56 pm
If your environ variables are properly set and exported then it might be a permission problem.
Check that your $GOROOT has the correct permissions 755. Your ~/bin should also be 755. You can fix either by using chmod on each directory. Example: ‘chmod -R 755 ~/bin’
Check that you’re not running the ‘./all.bash’ script under sudo. There have been some reports of errors if you run it under sudo.
If this doesn’t help, you should try posting your error to the GoLang-Nuts google group.
#8 by foobar on November 16, 2009 - 1:05 am
FYI, if you intend to contribute back to Go, the codereview extension requires mercurial > 1.3
Pingback: Installing Go on Mac Leopard « Scotsman on a Horse
#9 by Hugh Lynch on November 18, 2009 - 12:59 am
Thanks a bunch for the write-up. The installation went smoothly. I’m curious about the Python requirement. I installed Python per your recommendation, but I didn’t see the requirement on golang.org.
#10 by kelvin.wong on November 18, 2009 - 2:51 am
Mercurial is the source control management tool for the Go Language. Mercurial requires Python 2.4 as it is written in Python and C. Once they start distributing Go in other formats (tarballs, deb, dmg, msi, etc) you probably won’t need to install it in order to compile Go.
#11 by Hugh Lynch on November 18, 2009 - 3:50 am
spoke too soon… my build hung in the test phase:
mandelbrot
meteor-contest
pidigits
threadring
chameneosredux
— cd ../test
I never get to:
0 known bugs; 0 unexpected bugs
#12 by gzmask on November 20, 2009 - 7:39 am
I got tis:
— cd ../test
1 known bugs; 0 unexpected bugs
what and where is teh “1 known bugs”?!
#13 by Michele -BaNzO- Zamboni on November 23, 2009 - 5:00 pm
Same problem as Hugh Lynch for me. I am running Snow Leopard 10.6.2
Any hints?
Ciao,
Mic
#14 by Anthony on November 24, 2009 - 8:57 am
At this point as well my compilation has been going and pegging the CPU at 50%. Here are the results from my uname -a command:
Darwin Anthonys-OSX.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386.
Hopefully this is compatible with snow leopard. I will retry it again.
#15 by Ben on November 24, 2009 - 4:36 pm
Hugh, did you manage to figure out what the problem is? I get exactly the same result — every thing goes fine until the last line:
â cd ../test
I never get to:
0 known bugs; 0 unexpected bugs
Also, I installed python 2.6.4 — Wongo refers to version 2.5.2 of python. might that be the issue?
Thanks for any help.
#16 by Paul on November 26, 2009 - 3:25 pm
@Hugh Lynch
It’s a known bug issue. You will find the discussion here:
http://groups.google.com/group/golang-nuts/browse_thread/thread/d6780486702fddbd#
Basically, go into ~/go
type “hg pull -u” which will update to the bleeding edge of go
then re-run ./all.bash in ~/go/src
#17 by Stefan on December 31, 2009 - 3:22 am
Had to add the following to ~/.profile (for Mac OS X 10.5):
export C_INCLUDE_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/include
export LIBRARY_PATH=/Developer/SDKs/MacOSX10.5.sdk/usr/lib