Quick Go Setup Guide on Mac OS X

Kyle C. Quest (Q)
Aug 9, 2017 · 4 min read

The latest stable version of Go is 1.14.1. The setup instructions below assume you are installing the Go 1.14.1. For other versions make sure to update the distribution link and hash information for the version you are trying to install (you can get it from the official download page https://golang.org/dl/ ).

Step 0: Remove the Old Installation of Go (if you have it)

Step 1: Download and Install Go

If the second command doesn’t print the sha256 string back then something is not right :-)

You can get the link to the current installation package from https://golang.org/dl/ . It’s also where you can get the sha256 checksum for the installer.

Step 2: Setup Your Go Workspace

The default (global) workspace for Go is $HOME/go. If you want to use another location set the $GOPATH variable explicitly in you .profile file (or its equivalent). Go 1.11 introduced the initial support for modules where you no longer have to rely on $GOPATH. With Go 1.14 Go modules are finally ready for production and they are no longer an experimental feature. See the official Go Modules wiki and blog posts to learn more about using modules. Use Go Modules unless you have a specific reason not to use them and if you do then you don’t need to worry about $GOPATH and where you put your project.

As a best practice you should also add the bin directory from your workspace to your PATH(in your .profile file).

Step 3: Install Additional Dev Tools

If you are using Go Modules for your new project you don’t need to install any additional dependency management tools. If you still want to use one of the 3rd party tools like dep then you need to install it too.

Regardless of the dependency management tool you use it’s a good idea to use vendoring and commit your vendor directory with your application project repository to guarantee that your application builds and you have the dependencies you expect, so if the network is down or if the dependency owner decides to make unexpected/breaking changes to the libraries your application is still ok. With Go 1.13 you also get the module proxy feature (using as the https://proxy.golang.org module proxy server by default), which reduces the need to vendor your dependencies in some cases.

Note that it’s not recommended to commit the dependencies if you are creating a library.

golint is one of the static analysis tools you should have. There are many other static analysis tools you can use, but golint with the built-in govet should be in your arsenal from day one. If you are using Go Modules and you want to install golint from the project directory make sure to add GO111MODULE=off in front of the command to install it otherwise golint will be added to our project’s go.mod file and that’s probably not what you want :-)

If you are using Github you can also add Go Report Card to your repo to provide additional code quality information.

Step 4: Create Your First Go App

Create the project directory first ( anywhere/<your_app_location> ):

Running go mod will produce go.mod for your project. Note that the module name/path must have a dot in it (you don’t have to worry about it if your module name has a Github path in it, e.g., github.com/your_github_username/your_project).

Add some code (in app.go ):

Build and execute your new app to verify that your Go installation is working:

With real apps you’ll need to do a lot more :-)

First, don’t forget about go fmt(to format your source code):

Then, run your static analysis tools (at least, golint):

And finally, build your app:

Note that if you don’t specify any filenames the name of the executable will match the name of the project directory. By default, the app executable is located in the same directory.

Step 5: Optional IDE Setup

Visual Studio Code is one of the top options for Golang IDEs. Give it a try!

Install Visual Studio Code

Download the current installation package from https://code.visualstudio.com/ .

Install the Go Extension

  • Click on the ‘Extensions’ icon (the last option on the navbar you’ll see on the left side of the IDE).
  • Type ‘Go’ in the search box.
  • Select the extension by Microsoft (used to be by lukehoban). It should be the first option in the search results.

If you want to debug your Go apps in Visual Studio Code you also need to install delve.

If you want an IDE, but you don’t like Visual Studio Code you can try GoLand from JetBrains or vim-go.

Next Steps

Make sure you go through the interactive Tour of Goto learn about the language and how to use it and then at a look at the 50 Shades of Go blog post to learn about the gotchas you might encounter. Once you are comfortable enough experimenting with toy projects take a look at the Go Project Layout post to get ideas about how to structure your Go projects.

golang-learn

All Things Go

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store