Thursday , 27 April 2017
Home » Installing Go Language on Mac OS X

Installing Go Language on Mac OS X

Here’s a simple quick tutorial on how to install Go Language from Google on the Mac OS X.

  1. Install XCode
  2. Install Macports
  3. Open Terminal and install mercurial from macports and wait.
    sudo port install mercurial
  4. Edit your .profile to include the Go environment variables. This is required to build the Go Language. Add the following:
    # wherever your Go source directory will be
    export GOROOT=$HOME/go
    # or 386 but it is recommended to use amd64
    export GOARCH=amd64
    export GOOS=darwin
    # export GOBIN=$HOME/bin # it will install the Go compiler here by default.
    # add the $GOBIN into your path environment if you want to.
    # export PATH=$GOBIN:$PATH
  5. Open a new Terminal to refresh the environment variables.
  6. Download the Go Language source codes
    hg clone -r release https://go.googlecode.com/hg/ $GOROOT
  7. Change directory to $GOROOT
    cd $GOROOT/src
  8. Build the source
    ./all.bash
  9. If there are no errors it will show the following:
    — cd ../test
    N known bugs; 0 unexpected bugs
  10. You can start using it now! 6g is the compiler filename for amd64 and 8g is the compiler filename for 386.

To update the source:

  1. Change directory to $GOROOT
    cd $GOROOT/src
  2. Update the source
    hg update
  3. Build the source
    ./all.bash
  4. If there are no errors it will show the following:
    — cd ../test
    N known bugs; 0 unexpected bugs

About Justin Lee

Check Also

Samsung Galaxy Note7 – “Eye-ing” the Next Evolution in the Galaxy Note Series

The next generation Samsung Galaxy Note7 combines both style and innovative features and top of …

4 comments

  1. Nice.. I am installing it right now.

    I hit on one error with mercurial..

    “File “/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/locale.py”, line 410, in _parse_localename
    raise ValueError, ‘unknown locale: %s’ % localename

    Python can’t find ‘Locale’.

    You can fix this by setting the LANG and LC_ALL environmental variables to UTF8.

    #export LANG=UTF8
    #export LC_ALL=UTF8

    I got the tip from

    http://old.nabble.com/-MacPorts—20730:-Mercurial-appears-to-require-LANG-and-LC_ALL-set-to-UTF8-td25039324.html

  2. OK. One more hurdle for OSX 10.5 install. If you’re default OSX user account is not admin (and it shouldn’t be!!) The you’ll need to do some more env variable settings to allow go to compile.. This will allows your GO environment variables to exist when you sudo..

    “You have to add the GO* environment variables to /etc/
    sudoers and add to the Defaults list with
    (Defaults env_keep += “GOROOT GOBIN GOOS GOBIN GOARCH”)
    so they are maintained when you run sudo.”

    Got it from http://groups.google.com/group/golang-nuts/browse_thread/thread/6db568d839310301/141ad6051469d289?lnk=gst&q=quietgcc#141ad6051469d289

  3. Oh? I didn’t use sudo to build the source. You needed to use sudo to compile?

  4. Yes.. Maybe cos of where I pointed GOBIN to.. Also I don’t run as an Admin account..

Leave a Reply