Skip to content

Latest commit

 

History

History

01-setup

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Setup Your Go Development Environment

In this section, you will setup your Go development environment. Upon completion of this section you should have achieved the following:

  • Installed the Go language for your OS.
  • Cloned this repository.
  • Configured the tutorial as your Go development environment.
  • Installed the Glide package manager.
  • Installed the IntelliJ Go plugin. If JetBrains products are not your thing, alternatives are provided.
  • Opened your first Go project.

Installing Go

OSX and Windows

  1. Download and install the latest 1.6.x version of Go for your OS from the Go download page.

  2. Navigate to the location you downloaded your OS installer to and double-click on the installer.

  3. Open a terminal/cmd window and type in go version and press enter. You should see output similar to the following:

    go version go1.6 darwin/amd64

That’s it! You are done installing Go for your OS.

Linux

Ubuntu

If you are running Ubuntu, the easiest way to install a recent version of Go is through the “Ubuntu containers team” lxd-stable PPA.

  1. Open a terminal window.

  2. Type in sudo apt-add-repository ppa:ubuntu-lxc/lxd-stable and press enter.

  3. Press enter when prompted to accept adding the lxd-stable repository.

  4. Type in sudo apt-get update and press enter.

  5. Type in sudo apt-get install golang and press enter.

  6. Open up a terminal/cmd window and type in go version and press enter. You should see output similar to the following:

    go version go1.6 linux/amd64

That’s it! You are done installing Go for Ubuntu Linux.

From the tarball

  1. Download the tarball of the 1.6.x version of Go for Linux from the Go download page.
  2. Follow the installation instructions for Linux found at the Go installation documentation page

Clone the tutorial repository

Next you will clone this tutorial repository.

  1. Open a terminal/cmd window and navigate to the directory from which you would like to clone this repository.
  2. Type in git clone https://github.com/rawlink/golang-intro and press enter.

Configure the Go development environment

Now that you have cloned the tutorial repository, you will configure it as your Go development environment. It is assumed that you know how to configure environment variables for your OS. You may need to adjust the examples for your particular OS.

  1. Point the GOPATH variable at the cloned tutorial directory. e.g. GOPATH=/home/rawlink/golang-intro
  2. Set the GO15VENDOREXPERIMENT environment variable to 1. e.g. GO15VENDOREXPERIMENT=1
  3. Add the $GOPATH/bin directory to your PATH. Don’t worry if this directory doesn’t exist, Go will create it for you. e.g. PATH=$PATH:$GOPATH/bin

Install the Glide package manager

The Glide package manager for Go can be found at it’s GitHub repository. Rather than follow the installation instructions contained in the GitHub repository, I encourage you to use the following steps.

  1. Open a terminal/cmd window.

  2. Type in go get -u github.com/Masterminds/glide and press enter. This will retrieve the dependency sources and Glide sources to the source directory, and build them into the pkg and bin directories inside of your $GOPATH.

  3. Type in glide -v and press enter. You should see output similar to the following:

    glide version dev

Install the IntelliJ IDEA Go plugin

The IDEA Go plugin is compatible with a large set of JetBrains platform IDEs (e.g. IntelliJ IDEA, WebStorm, Android Studio, etc.). It can be found at it's GitHub page.

To install it in IDEA (Other JetBrains platforms may be similar, but no guarantees):

  1. Follow the instructions on the JetBrains site to add the plugin. When you are adding the repository in step 4 of the JetBrains instructions, use the value https://plugins.jetbrains.com/plugins/alpha/5047 for the weekly build of the plugin.
  2. Open the Preferences dialog.
  3. Select the Plugins settings.
  4. Type go in the Plugins search field.
  5. Select the Go plugin and install it.

JetBrains alternatives

For those of you who are not using a JetBrains product, there are several other Go IDEs to choose from.

Open your first project

From within IntelliJ:

  1. Select File->Open.
  2. Navigate to the $GOPATH/src/02-hello directory.
  3. Select OK.
  4. Open hello.go in the project view.
  5. Click on the ‘Setup SDK’ link.
  6. Select your Go SDK. If it’s not available select Configure and perform the following steps:
  7. Click on + and select ‘Go SDK’.
  8. Navigate to your installation of the Go SDK. Most of the time, IntelliJ will have automatically selected the correct directory for you.
  9. Select OK in the file selection dialog.
  10. Select OK in the ‘Configure SDK’ dialog.
  11. Select OK in the ‘Select Project SDK’ dialog.
  12. Click on the ‘Change module type to Go and reload project’ link.
  13. Select ‘Reload Project’.

Next: Hello, Gopher!