Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save cdemers/bbbb85bcbc741a3b2a79f63e2cbe92d8 to your computer and use it in GitHub Desktop.
Save cdemers/bbbb85bcbc741a3b2a79f63e2cbe92d8 to your computer and use it in GitHub Desktop.
How to install a functional Go development environment on MacOS with Atom and all the bells and whistles.

Warning! This doc is pretty outdated, I'm rewriting it right now and I'll update this as soon as it's done.


Installing a Go development environment on Mac OS for Beginners

Installing Go

First, install the Go compiler from Google's Go Website: https://golang.org/dl/

Or just use this link to download the 1.8 version for Mac OS: https://storage.googleapis.com/golang/go1.8.darwin-amd64.pkg

Unless you have a good reason, you should probably avoid using package managers like brew, macports and fink to install Go.

How to Test

You should now be able to call this command and get the Go help text as an output:

/usr/local/go/bin/go

The output should be something like:

Go is a tool for managing Go source code.

Usage:

	go command [arguments]

The commands are:

	build       compile packages and dependencies

(etc)

Choose a GOPATH

This is a folder where all Go project will be placed and managed, if you dont know what to choose, you can use ~/golang.

mkdir ~/golang

Now remember the full path to this folder, you will need it later. You can get it this way:

cd ~/golang
pwd

You will probably obtain something like:

/Users/cdemers/golang

How to Test

Doing the following should not return an error:

cd ~/golang

Create a setenv.sh file

Move in your previously created GOPATH folder and create a file named setenv.sh, this file will contain the following except that the GOPATH variable must match your own GOPATH:

# (Notice that there is no #!/bin/bash here)
export GOPATH=`cd ~/golang && pwd`
export GOROOT=/usr/local/go
export PATH=$PATH:$GOPATH/bin

You don't need to set this file as executable, you will source it, not execute it.

How to Test

Doing the following should not return an error:

source ~/golang/setenv.sh

And afterward, doing the following:

echo $GOPATH

Should return something like:

/Users/cdemers/golang

And also, you should now be able to call this command and get the same Go help text as an output as before:

$GOROOT/bin/go

The output should be something like:

Go is a tool for managing Go source code.

(etc)

Installing the Base Go Tools

Now you are ready to install some very useful Go tools, after sourcing the setenv.sh file, run the following four commands:

go get -u github.com/nsf/gocode
go get -u golang.org/x/tools/cmd/cover
go get -u github.com/alecthomas/gometalinter
go get -u github.com/zmb3/gogetdoc
go get -u github.com/tools/godep

gometalinter --install --update

or, if $GOPATH/bin is not in your path:

$GOPATH/bin/gometalinter --install --update

If the previous steps were successful, these commands should work without any problems. You should now have a bunch of new command line tools located in $GOPATH/bin (which in our case should translate to something like /Users/cdemers/golang/bin).

How to Test

The following should return the gocode file, and not return an error:

ls $GOPATH/bin/gocode

The following should return the cover file, and not return an error:

ls $GOPATH/bin/cover

The following should return the golint file, and not return an error:

ls $GOPATH/bin/golint

If the previous tests were successful, the installation of these tools should be ok. However, if you want to be very thorough, you can validate that the $GOPATH/bin folder contains at least all the following files:

aligncheck        deadcode          errcheck          goconst           goimports         gometalinter      gotype            interfacer        staticcheck       unconvert         cover             dupl              gocode            gocyclo           golint            gosimple          ineffassign       lll               structcheck       varcheck

The Atom IDE

Now, you are ready to install the Atom IDE, which, as of now is the most suited for Go development. This will likely change in the future, but for now, if you want a good support for Go in a nice IDE environment, you have to go for Atom.

The first step is to install the Atom IDE, which is opensource and free. You can download it from the home page of: https://atom.io

This will provide you with a zip file, you only have to unzip it and move the resulting Mac OS application to your /Applications folder.

Next, enable the Atom command line tools by starting Atom, then clicking on the Atom menu in the top menu bar, then click on Install Shell Commands, and then you are ready to move on.

How to Test

To test that the Atom command line is working, simply execute the atom command in a terminal:

atom

As a result, Atom should start.

To test that the apm command line is working, simply execute the apm command in a terminal (you need to have started Atom at least once before, so that it will install the apm cli):

apm

As a result, you should have the help text of the apm command line, which look like this:

apm - Atom Package Manager powered by https://atom.io

Usage: apm <command>

(etc)

Install the Atom extensions for Go

To enable all the Go capabilities of Atom, you have to install a couple of extensions. This is the last step and is quick and easy. In a terminal and execute the following command:

apm install go-plus go-config go-rename environment file-icons highlight-selected minimap minimap-highlight-selected monokai

The CLI should give you confirmation that all went well, and you are now ready to Go.

One last thing, for your environment to work properly, you must start Atom using the command line from a terminal, and you must have sourced the setenv.sh file first:

source ~/golang/setenv.sh

And then you are all set, start Atom from the same terminal:

atom

And start building wonderful things!

@aphive
Copy link

aphive commented May 2, 2018

Getting the following:

Installing go-config to /Users/cayobuay/.atom/packages ✗
Request for package information failed: Not Found

Can't find it in the packages either... https://atom.io/packages/search?utf8=%E2%9C%93&q=go-config&commit=Search

@medikent
Copy link

medikent commented May 3, 2019

Gometalinter recommends upgrading to golangci-lint: github.com/golangci/golangci-lint/cmd/golangci-lint

And, for a module-compatible geocode you can upgrade to stamblerre/gocode: github.com/stamblerre/gocode

@cdemers
Copy link
Author

cdemers commented Jun 1, 2019

Thanks for the comments, this gist is pretty old and things have evolved a lot since, I'll rewrite it all soon.

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