Saturday, December 4, 2010

Installing Go language on Mac OS X

I have tried the Go language from Google on Ubuntu few months ago. Now I tried it on my Mac OS X box and see whether it works on machines other than Linux box. Mac OS X is based on BSD, so I guess the difference won't be that much. Mac OS X runs on intel x86_64 architecture, and Go language supports that.
Go supposes to run well on machine with GCC, Mercurial, and Bash. Mac OS X has them all. To my surprise, I already have Mercurial on my Mac OS X box!

I created the /swdevel/golang/hgco. Then checkout from the Mercurial repository from Google Code.

I am following the instruction given here http://golang.org/doc/install.html

$ hg clone -r release https://go.googlecode.com/hg/ go
requesting all changes
adding changesets
adding manifests
adding file changes
added 6822 changesets with 26893 changes to 3944 files
updating to branch default
2435 fles updated, 0 files merged, 0 files removed, 0 files unresolved

It succeeded checking out from the Mercurial repository!

$ cd go/src/
$ ./all.bash
...
...
--- cd ../test
1 known bugs; 0 unexpected bugs

---
Installed Go for darwin/amd64 in /swdevel/golang/hgco/go.
Installed command in /swdevel/golang/hgco/go/bin.
*** You need to add /swdevel/golang/hgco/go/bin to your $PATH. ***
The compiler is 6g.

On OS X the debuggers must be installed setgrp procmod.
Read and run ./sudo.bash to install the debuggers.

Well, they warned me for a known bug!
The system doesn't seem to get the processor correctly, AFAIK my Mac Mini supposed to be Intel Core2 Duo while it detects amd64?!?

It displays a bunch of compilation messages. It took somewhere around 8 minutes on my Mac OS X box.
The 6g denotes that your architectures is x64, while 8g is for x86.

Then I need to do this:
$ echo 'export PATH=/swdevel/golang/hgco/go/bin:$PATH'>> ~/.profile

$ cat ~/.profile
Check whether you have exactly code below in the last line of your ~/.profile
export PATH=/swdevel/golang/hgco/go/bin:$PATH

Close your shell window, and open a new one (this is an important step so that your ~/.profile will be executed!).

Test on the new shell window:
$ 6g
It should displays something like this:
gc: usage: 6g [flags] file.go...
flags:
-I DIR search for packages in DIR
-d print declarations
...
...
-x print lex tokens

Done installation!
Next post will be showing the hello.go (hello world of Go language) on the Mac OS X box.

No comments:

Post a Comment