Published using Google Docs
Installation of the Golang environment
Updated automatically every 5 minutes

Install Go

Verify the dependencies

Go needs the git command to be installed and added to the environment variable PATH.

Install the SDK

Download the latest version of Go on the official website: https://golang.org/dl/

Choose the right distributable depending on your platform.

The installation wizard will install a copy of the Go SDK on the local hard drive and add the directory where the go binary lives to the system variable PATH.

Check the installation

$ go version

go version go1.9 darwin/amd64

Configure the workspace

When compiling a go package, go will search for imported dependencies in the following directories:

GOPATH is the directory where all the go source files live. It is in that directory that the third-party packages that your packages depend on are stored, as well as your packages themselves.

Most packages follow the convention below:

$GOPATH/src/<name_of_the_git_server>/<namespace>/<package_name>

For example :

$GOPATH/src/github.com/gorilla/mux

Define the environment variable GOPATH, with a personal directory. For example :

/home/johndoe/gocode

Then add that directory to the environment variable PATH :

$GOPATH/bin (Mac / Linux) or %GOPATH%\bin (Windows)

Check that everything is ok

Use the following command to download and install the goimports tool:

$ go get golang.org/x/tools/cmd/goimports

$ goimports --help

Install GoLand

Download the Intellij GoLand IDE at this address: https://www.jetbrains.com/go/download/

Hint: when opening a project, open the settings window of the IDE, then go in Go > Imports, choose goimports as a value for the Sorting type option, and check all the boxes below.

Alternatives