Skip to content

Instantly share code, notes, and snippets.

@jiajun86
Last active August 14, 2017 03:10
Show Gist options
  • Save jiajun86/d6452d8c8a593b22e48f846201d45df1 to your computer and use it in GitHub Desktop.
Save jiajun86/d6452d8c8a593b22e48f846201d45df1 to your computer and use it in GitHub Desktop.
Getting Started with Go 1.8 on macOS Sierra Version 10.12.3

Getting Started with Go 1.8 on macOS Sierra Version 10.12.3

I spent substantial amount of time when first setting up my Go development environment on macOS Sierra Version 10.12.3 as it is not as straight forward as I expected it to be. After going through numerous hiccups, I finally managed to get it done. So, I would like to share my experience with new Go developers to help them speed up their preparation process.

Get Started in 6 Easy Steps

  1. Download and install Go via
  2. Test your Go installation
  3. Prepare your Go workspace
  4. Download and install gdb via
  5. Configure gdb
  6. Test your gdb installation

1. Download and Install Go

You may choose to download and install Go via official binary distribution, Homebrew or Go Version Manager (GVM). This guide will walk you through using the official binary distribution.

Download the Mac OS X package installer, open it and follow the prompts to install the Go tools. The package installs Go to /usr/local/go and exports /usr/local/go/bin directory in your PATH environment variable.

2. Test Your Go Installation

Restart any open Terminal sessions for changes to take effect. Enter go version in Terminal and it should show: go version go1.8 darwin/amd64.

3. Prepare Your Go Workspace

A Go workspace is a directory hierarchy with three directories at its root:

  • src contains Go source files
  • pkg contains package objects
  • bin contains executable commands

You may place your Go workspace anywhere. This guide will use the following as example: $HOME/Development/go.

Enter mkdir -p $HOME/Development/go/{bin,pkg,src} in Terminal and it shoud create your workspace directories. You need to tell Go to use this as your default workspace by exporting it as GOPATH variable.

Enter vi $HOME/.bash_profile in Terminal and append the following line to it: export GOPATH=$HOME/Development/go, then save and exit. Restart any open Terminal sessions for changes to take effect.

Enter go env in Terminal and verify that GOPATH is pointing to $HOME/Development/go/.

4. Download and Install gdb

Download and install gdb via Homebrew by entering brew install gdb in Terminal. Restart any open Terminal sessions for changes to take effect.

5. Configure gdb

Before you can use gdb for debugging Go, you need to perform 2 prerequisites:

  1. Create code signing certifacte for gdb
  2. Create .gdbinit script for gdb

Create Code Signing Certificate for gdb

  1. Open Keychain Access application (can be found in Applications/Utilities directory or through Spotlight). Click on Keychain Access > Certificate Assistant > Create a Certificate... in the application menu.
  2. Enter gdb-cert as Name, select Self Signed Root as Identity Type, select Code Signing as Certificate Type and check Let me override defaults
  3. Enter 3650 as Validity Period (days) (Maximum validity period is 20 years)
  4. Keep clicking on Continue to skip the next six screens until you see the one entitled Specify a Location For The Certificate
  5. Select System as Keychain and click on Create (If prompted, type in your password)
  6. Click on System under Keychains in the sidebar on the left of Keychain Access application
  7. Double click on gdb-cert from the list
  8. Select Always Trust as When using this certificate by expanding the Trust section in the information window that appear
  9. Enter killall taskgated in Terminal to restart the Taskgate access-control service
  10. Enter codesign -s gdb-cert /usr/local/bin/gdb in Terminal and enter your password if prompted. gdb is successfully signed if there is no ouput in Terminal

Create .gdbinit for gdb

Enter vi $HOME/.gdbinit in Terminal and append the following line to it: set startup-with-shell off, then save and exit. Restart any open Terminal sessions for changes to take effect.

6. Test Your gdb Installation

You may test your gdb installation by creating a simple Go program, adding breakpoints to it and start debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment