Contents Page Next

The Goblimey Scaffolder

1.1 Installing Go

Instructions for installing Go are here

That document shows several ways to install Go. It's a very good idea to install it from source code, but that's not the simplest option. If you are running under Windows and you just want to get started quickly, the MSI installer is simpler, but there is a cost to going down that route. On every new release of Go, you will have to wait for the MSI installer to become available. If you want to keep up-to-date with latest releases, you should follow the source code option.

Once you have installed Go, you need to read the document How to Write Go Code which describes how to set up your Go environment.

As that document explains, you can keep all your Go projects together in one directory (AKA folder), and that needs to be defined by an environment variable GOPATH. I'm going to assume that you will use a directory called goprojects in your home directory.

My user name is simon so under Linux my home directory is /home/simon. Under Windows it's C:\Users\simon.

In the examples below, "$ command" represents a command that you issue in a Linux command window. The "$" represents the prompt that the command window gives you. Type the command (without the dollar) and press the enter key to run it.

Using your command window, create your project directory:

$ mkdir goprojects

Set the GOPATH environment variable and add the workspace's bin subdirectory to your PATH.

Under Linux:


    $ export GOPATH=/home/{your user name}/goprojects
    $ export PATH=$PATH:$GOPATH/bin
	
In my case, that would be:


    $ export GOPATH=/home/simon/goprojects
    $ export PATH=$PATH:$GOPATH/bin
	

That only sets those variables for that command window. You should also add the same commands to the file .profile in your home directory so that they are run every time you log in and apply to all command windows.

Under Windows 7:

Go to the control panel in the Start menu. Choose System, then System Security. In the left-hand menu, choose Advanced System Settings.

That produces a pop-up window with a button marked Environment Settings. Press that and the Environment Variables window appears. In the list of user variables at the top, there should be one called Path. It's a list of directories separated by semicolons.

Use the New button to create an environment variable called Path set to "c:\Users\\{your user name}\goprojects". In my case, that's "c:\Users\simon\goprojects".

Still in the Environment Variables window, find the user variable called Path and select it. Press the Edit button.

Run to the end of the line (it may be quite long) and add a semicolon followed by the GOPATH bin directory:


	;c:\Users\{your user name}\goprojects\bin
	

Press OK to make the change.

Given that you have already created a variable GOPATH containing most of that text, you could instead add this to the Path:


	;%GOPATH%\bin
	

Either way, don't forget the semicolon.

Those variables will be available to all command windows that you open from now on, but NOT to any that you already have open.

Don't get confused between the PATH and the GOPATH variable. PATH tells the system (Windows, Linux or whatever) where to find executable programs. GOPATH tells the Go tools where to find Go projects. Both contain a list of directories (folders). Under Windows, the items in the lists are separated by semicolons, under Linux by colons.

Contents Page Next