Sunday, June 2, 2013

Installing Go, Gocode, GDB and LiteIDE

This is a great post by Wade Wegner for installing Go on your Windows Machine:

Mac OS X

The following instructions will guide you through installing Go on your Mac.

Step 1: Download Go

Open your favorite browser and go to the following website:

This will show you all the latest builds for the different operating systems. Darwin is the name for the Mac OS. Download the installer package for your OS version and architecture.

Once downloaded go to your Downloads folder in Finder and double click on the pkg file to start the installation. The installation will put Go in /usr/local/go. Once the installation is complete you will want to check the installation.

Note: Moving forward we will be using both Terminal and Finder. It helps to be able to see all the files in Finder.  Finder by default will not show you everything that is on your hard drive.

To show all files in Finder:

Open a Terminal session. If you don't know where the Terminal program is go to your Applications folder in Finder and then Utilities. Click on Terminal and a bash shell command window will open.

Execute the following commands in Terminal.

defaults write AppleShowAllFiles TRUE
killall Finder

The killall Finder will reload the Finder program and now you can see all the files.

Step 2:  Check Installation

Open a Terminal session and type the following command

go version

You should see the following if everything installed correctly

go version go1.4 darwin/amd64

Now type the which command to verify the installation is in /usr/local/go

which go

You should see that Go can be found in /usr/local/go/bin


Now Go is installed but we are not ready to start programming just yet. In order to get intellisense when we are using LiteIDE we need GoCode.

Step 3:  Set Your GOPATH

You need a single place to store and work on your Go projects. Create a folder called Projects from inside your home folder:

cd $HOME

mkdir Projects

Now set this as your GOPATH. Open the .bash_profile file from the $HOME folder and add the following items to the end.

nano .bash_profile

export GOPATH="$HOME/Projects"
export PATH=$PATH:$GOPATH/bin

Then exit the Terminal App and open a new Terminal App. Check that the Go environment now has your new GOPATH.

go env

You should see all the Go related environment variables including GOPATH. Here are some of them:


Step 4:  Get, Build and Install Basic Packages

These are Go packages you may want:

// gocode is used by many editors to provide intellisense
go get

// godoc is used by many editors to provide documentation support
go get

// vet should be run after every build to check your code
go get

// goimports is something you should run when saving code to fill in import paths
go get

// gorename is used by many editors to provide identifier rename support
go get

// oracle is a tool that help with code navigation and search
go get

// gotype is used by many editors to provide Go support
go get

// golint should be run after every build to check your code
go get

Step 5:  Install GDB


Installing the new version of GDB is going to be a unique experience for most. The other problem is that you most likely have a version already installed on your machine.

Run this command in Terminal

gdb --version

If you are like me the following information will be provided

GNU gdb 6.3.50-20050815 (Apple version gdb-1705)

Now run this command in Terminal

which gdb

This version of gdb is installed under


So why is this important? When we build and install the new version of GDB it will be installed under /usr/local/bin. Remember Go was installed under /usr/local/go. I don't understand why some programs are installed under /usr/bin or /usr/local/bin or even why you can find different version of the same binary under both. When we are done this is exactly what we will have.

Open your browser again and go to the following url:

You will see the following on the page

Click the link called and you will see a list of files you can download

Download gdb-7.8.tar.gz from your browser and then find the file in Finder inside the Downloads folder. Double click on the file in Finder and Finder will unzip the file to a new folder called gdb-7.8.

Go back to your Terminal session and navigate to the gdb-7.8 folder in Downloads

cd ~/downloads/gdb-7.8

You need to run two commands from Terminal that will build the source code.


If the make command does not work then install XCode. I had XCode installed on my machine prior to running these commands. XCode installs the compilers that are used to build code.

Also, I found with version 7.8 the make failed because of some errors. If this is happening, remove the unzipped folder, unzip the tar.gz file again and use this parameter with the configure call.

./configure --disable-werror

Once the make command is done we need to install this version of GDB to /usr/local/bin.

In Terminal run the following command

sudo make install

Once this command is finished the new version of GDB will almost be ready for use. Remember we now have two version of GDB installed on the machine. From inside of LiteIDE this will not be a problem but from Terminal it is.

Run the following command in Terminal again

gdb --version

You still get the old version

GNU gdb 6.3.50-20050815 (Apple version gdb-1705)

Now run this command in Terminal

which gdb

The old version of gdb is still being used


So why is this happening? Because your PATH has /usr/bin before /usr/local/bin. We can fix this for our current Terminal session by running the following Terminal command.

export PATH=/usr/local/bin:$PATH

This command will update the PATH and put /usr/local/bin at the front.  Now run the GDB version command again.

gdb --version

Now you get the new version

GNU gdb (GDB) 7.8

Now run this command in Terminal

which gdb

This version of gdb is being used


Unfortunately this is not permanent.  If you open a new Terminal window the PATH variable will go back to the original setting. So how do we make /usr/local/bin always come before /usr/bin in the PATH every time we open a Terminal session?

You will need to modify the paths file under the /etc folder.

cd /etc
sudo nano paths

In my original version of the paths file I added the following entries:


Just move /usr/local/bin to the top and save the file:


To see if the change worked, open a new Terminal session and echo the PATH:

echo $PATH

To get more information about how to use the GDB check out this website. You can run these GDB commands from inside of LiteIDE so this web page is helpful.

Now that GDB is installed we need to do one more thing, codesign the binary so it can be used to debug the programs we write.

NOTE: Please review the GDB Problems at the end of the article 

Step 6: Codesign GDB


If we don't codesign the GDB executable LiteIDE will run in debug mode but it won't work. The steps I have provided come from the following websites.

NOTE: Make sure you have the latest version of Xcode installed before you continue

5a. Creating a Certificate

Start the Keychain Access application

Open the Menu option
/Keychain Access/Certificate Assistant/Create a Certificate...

In the Create a Certificate dialog box use the following settings

Name: gdb-cert
Identity Type: Self Signed Root
Certificate Type: Code Signing
Let Me Override Default:  Checked

Click Continue several times until you get to the Specify a Location For The Certificate screen

Keychain: System

If you can't store the certificate in the System keychain, create it in the login keychain, then exported it. You can then imported it into the System keychain.

Then find your new certificate in the list and right click and select Get Info. Then expand the Trust item and find the Code Signing drop down. Change the setting for Code Signing to Always Trust. You must quit the Keychain Access application in order to use the certificate so close the program.
5b. Codesigning GDB with new certificate

Before you run the codesign command in Terminal you need to add an export to your Terminal session or you will get the following error

object file format unrecognized, invalid, or unsuitable

Open or reuse your existing Terminal session and run the following export command

export CODESIGN_ALLOCATE="/Applications/"

Now change the directory in your Terminal session to where the GDB binary is located and codesign the binary.

cd /usr/local/bin
codesign -s gdb-cert gdb

There should be no errors and a new Terminal command prompt should just appear. Now everything is ready to go. We have Go, Gocode and GDB installed. Next we need a development editor.

Step 7: Install Editor


DisposaBoy wrote this plugin for Sublime

Mark Wolfe wrote this post:


Victor Farazdagi wrote this post on installing Vim for Go:


Joe Fitzgerald wrote this plugin for Atom


LiteIDE is an excellent IDE and I love working in it. Installing and getting it going requires just a few steps.

Open your browser and navigate to

Chose the Mac version ( Download the file and then open Finder and navigate to the Downloads folder.

Unzip the file and copy into the Applications folder.

Open your Applications folder and double click on LiteIDE to start it.

Step 8: Test LiteIDE

Let's create a new program and test our installation

Switch to LiteIDE and find the View menu option.  Select the Manage GOPATH option at the bottom of the menu. The Manage GOPATH dialog box will appear.

You need to add the Projects folder you created in step 3 as a custom directory for your GOPATH. This is where Go will look for custom packages and the code you are writing. The Go libraries will always be available. To learn more about the GOPATH go to this web page:

Choose File/New and perform the following tasks.

1. Double click on your custom GOPATH. It will be cut off in the dialog box but it should show above the system folder /usr/local/go. This should change the Location field to the GOPATH.

2. Select Go1 Command Project.

3. Name your new program test_program.

4. Click OK and agree to open main.go.
Before you build and test the program make sure you are using the correct build environment (darwin64-local).

Test if you can build and run the program. Find the blue "BR" button and select it. If LiteIDE is configured correctly the program should build and run. The Build Output should look like the image below.

You should see the Hello World! print in the Build Output window.

Next test if the debugger is working. Select line 9 of the program and click on the orange button to add a breakpoint.

Next you need to change the Build configuration a bit. Add these build arguments. They help support the GDB. The debugging is not perfect but this makes it better. The debugger will work without it but my experience is that the debugger can pick up more information.

-gcflags "-N -l"
(Capital N and Lowercase L)

To learn more about debugging in Go click on this link:

Now from the Debug menu select Start Debugging.

If the debugger is working a green arrow will stop at line 8. You may be asked to enter your password before debugging begins.

If this is happening you are good to go.
If things stop working always double check that you have the right environment selected (darwin64-local). I can't tell you how much time I have lost because the environment changed without me realizing it.

Possible Build Errors

"can't open output file for writing: a.out, errno=13 for architecture x86_64"
Solution By: Alejandro Gaviria
Version: Xcode 4.2, Mac OS X (10.7.1), Mac OS X (10.7.2)

This is due to the gcc compiler that comes with XCode ~4.1.

Solution comes from this Apple discussion thread:

Possible GDB Errors

"Unable to find Mach task port for process-id 12383: (os/kern) protection failure (0x2).\n (please check gdb is codesigned - see taskgated(8)"
Solution By: Karl Tuhkanen
Version: Mac OS X (10.8)

1. sudo chgrp procmod /usr/local/bin/gdb
2. sudo chmod g+s /usr/local/bin/gdb
3. add the legacy switch -p to taskgated by modifying the file System/Library/LaunchAgents/
4. Force kill taskgated process (it will restart) or reboot if necessary

Solution comes from this stackoverflow thread:

ALERT! Be sure to use standard .plist markup with the file modification. Otherwise OSX won't start next time you reboot. This happened to me. Solution to this is to reboot with recovery option (Cmd-R) and modifying the file with vi to match the standard.

Version 7.6.2 still has a bug that prevents it from loading the Go runtime integration!
Solution By: Chris McGee
Version: Mac OS X

You can see the problem when you fire up GDB and it does not have the special "Loading Go Runtime Support" message. There is a patch for this:

GDB Freezes And Consumes CPU When Using "Info Locals"
Solution By: Chris McGee
Version: Mac OS X

GDB freezes. Only Ctrl-C seems to bring it back. When using an application that uses gdb/MI for a GUI interface gdb is totally unresponsive.


I hope these instructions get you up and running with Go quickly on your Mac. Now that you can write code using LiteIDE I suggest building some test programs and learning how all the different windows in the IDE work. There are a lot of great goodies in there.

Check out this web page:

It is the Go language resources page and contains a lot of great links to information. The Book Go In Action by Brian Ketelsen, Erik St. Martin and myself is available and being written for developers new to Go.

Here are other links to web pages that will be very helpful:

You must watch these videos on Go Concurrency Patterns


  1. Debugging worked after a few additional steps to these instructions.
    1. sudo chgrp procmod /usr/local/bin/gdb
    2. sudo chmod g+s /usr/local/bin/gdb
    3. add the legacy switch -p to taskgated by modifying the file /System/Library/LaunchAgents/
    4. Force kill taskgated process (it will restart) or reboot if necessary
    5. Try again

    Solution comes from this stackoverflow thread:

    ALERT! Be sure to use standard .plist markup with the file modification. Otherwise osx won't start next time you reboot. This happened to me. Solution to this is to reboot with recovery option (Cmd-R) and modifying the file with vi to match the standard.

    1. Karl, can you tell me what problems you experienced or what didn't work for you that required these steps. I would like to add these steps to the document. I didn't run into these problems. I am running version 10.8.4 of the Mac OS.

  2. I got this error from debug console from Lite-IDE --> "Unable to find Mach task port for process-id 12383: (os/kern) protection failure (0x2).\n (please check gdb is codesigned - see taskgated(8)". This error came even though I had codesigned gdb 7.6 with the exact steps of your instructions. Now I can reproduce the error by unloading the /System/Library/LaunchDaemons/, deleting the -p switch and reloading taskgated. My Mac OS is same as yours.

    The problem has to do with codesigning, but I can't figure out in what way.

    1. Thank Karl, I have added the error your identified and the solution to the post

  3. Great article! I only ran into one problem when builing and running LiteIDE test_program. "Errno 13." This is due to the gcc compiler that comes with XCode ~4.1.

    If anyone runs into Errno 13 please go here "Apple Discussion"

    1. Thank Alejabdro, I have added the error you identified and the solution to the post

  4. Thanks this was a great help.

  5. I ran into one small problem with the codesign command: gdb: cannot find code object on disk.
    Turns out codesign_allocate moved:
    export CODESIGN_ALLOCATE="/Applications/"

    The locate command found it for me (as well as regular use of /usr/libexec/locate.updatedb).

    1. Thanks for the update. I have made the change. The latest update of Xcode changed the location. I really appreciate it !!

  6. Thanks for the outstanding walk-through. I tripped over the nomenclature for "users" folder a couple of times, and simply guessed. Also, I was unable to get the line-8 green arrow rendered, and I have some work to do on getting the debugger working. I am using an early-1989 iMac, so darwin32-local was necessary for me to do a build; and I was using OSX 10.8.3 with the latest compatible XCode.

    Overall, really extraordinary job.

    Many thanks,


    1. I did focus the article on a 64-bit architecture, sorry about that. I am glad it had enough to get you going. If you have any questions send them to me.

    2. I wrote this back when I knew nothing about the os. I fixed all the references to user directory to home. Thanks again !!

  7. If you are into brew[0], the installation of go is dead simple[1] and I've found the upgrade process painless. GDB[2] is still a bit of a pain.

    [0] :
    [1] : "brew install go gdb"
    [1] ;

  8. Thanks for this walk-through. Having an integrated debugger is my main reason for using an IDE, instead of just an editor and Make, and after this I was up and running!

    You spent a big chunk of the post fiddling with the .bashrc file and PATH variable. There's a much easier way to do this on *nix systems (including OS X): edit the /etc/paths file. In this case you want the line "/usr/local/bin" to be before "/usr/bin". And you can add an entry for /usr/local/bin if it doesn't exist.

    1. Thanks for the tip on the /etc/paths file. I knew about that file. Beware that debugging on the Mac using GDB is not complete, though basic debugging works.

    2. Updated the post to use the paths file. Thanks Again !!

  9. Ouch, that's a lot of work just to get Go installed. For me on Linux, all I had to do was run `sudo pacman -S go` (`apt-get install go` for Debian/Ubuntu users) and done, could just open up my Kate text editor and enable the built-in terminal, save the file as go source code and have go syntax highlighting, write the code and save, type go run source-code.go and done.

  10. This comment has been removed by the author.

  11. Thank you very much, I only had to change one c file to work on yosemite in GDB project
    #import machine/setjmp.h to setjmp.h in gdb/darwin-nat.c. before ./configure command

    1. Thanks for sharing that. Can you send me that change so I can publish it :)