Installation & Setup¶
The first thing we need is a working Go installation on our system. The following instructions were derived from the official Getting Started documentation.
Binary distributions of Go are available for the FreeBSD, Linux, Mac OS X, NetBSD, and Windows operating systems from the official downloads page.
Building from Source¶
Many developers prefer to install Go directly from the source code. Building is easy and quick - the Go compiler and tool chain can be compiled in a matter of minutes on even a modest workstation or laptop.
Install Build Tools¶
The Go tool chain is written in C. To build it, you need a C compiler installed. You will also need the Mercurial DVCS tool to download the source. On Ubuntu run the following command to install the necessary packages:
$ sudo apt-get install gcc libc6-dev mercurial
Fetch the repository¶
Go will install to a directory named
go. Change to the directory that will
be its parent and make sure the
go directory does not exist. Then check out
$ hg clone -u release https://code.google.com/p/go
To build the Go distribution, run
$ cd go/src $ ./all.bash
If all goes well, it will finish by printing output like:
ALL TESTS PASSED --- Installed Go for linux/amd64 in /home/you/go. Installed commands in /home/you/go/bin. *** You need to add /home/you/go/bin to your $PATH. ***
where the details on the last few lines reflect the operating system, architecture, and root directory used during the install.
These instructions assume Go is installed at
~/go. If you installed
elsewhere, change the commands to reflect your actual installation path.
The Go tools look for several environment variables. Typically these are set in
your shell profile. If you are using Bash, add the following lines to your
export GOBIN=~/go/bin export GOARCH=amd64 export GOOS=linux export GOROOT=~/go
You probably also want to add the path to your
go/bin directory to your
~/.bashrc file to active the new environment variables. Once
go binary is on your
PATH, you can confirm your install is working
correctly by running the
go version command.
$ go version go version go1.1.1 linux/amd64
Go bindings are available for many popular programming editors and IDEs. As Go is still a relatively young language, none of these bindings are as full-featured as those for a mature language like Java. However a good integrated development environment, even if not perfect, is still a valuable tool.
Currently (July 2013) the IDE with the best Go support is Intellij IDEA.
Download the Free community edition of Intellij IDEA appropriate for your platform from the official download page.
Untar the downloaded tarball, descend into the resulting folder, and start Intellij by running:
Install Go Plugin¶
Open the Settings window (
File -> Settings) and go to
IDE Settings. Click on
Browse repositories, and type “golang” into the
search form. There should be only one result, “golang.org support”.
Double-click on it to install, and close the settings. You will be prompted to
If you like vi-keys, you may also wish to install the