This guide will show you how to install all the software needed to write programs in Go. Choose your operating system:
In OSX you can bring up the terminal by hitting CMD-Space (to bring up
spotlight), typing Terminal
and hitting enter.
Terminals are a text-driven interface to your computer. You can enter commands by typing the command and hitting enter. Your computer will then execute the command and display any results.
Terminals also allow you to manipulate files and folders on your computer.
You terminal starts in a working directory
where you can list
the folder contents with ls
, change directories using
cd
, make directories using mkdir
and remove
files using rm
.
Homebrew is a package manager for OSX. To
install it open a terminal (CMD
+space
, type
terminal
and then enter
) and then paste the
following command:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Git is a version control system used by most 3rd party Go packages. You can install it with Homebrew by running:
brew install git
GitHub's Atom is an excellent general purpose text editor which also has a very good Go plugin. Download it from atom.io/download/mac and install it by dragging it to your Applications folder in Finder.
For better go support we also need to install the
and go-plus
plugin. Go to Atom
-> Preferences...
->
Install
, search for go-plus
and click Install
. When
that is finished exit Atom.
The Go toolchain is required to build Go programs. You can download an
installer from golang.org/dl. Choose
the latest version available for OSX (eg
go1.4.2.darwin-amd64-osx10.8.pkg
) and run it.
Google's App Engine is a managed platform for web applications. If you aren't interested in installing App Engine you can skip this step.
Download the Google App Engine SDK for Go
from:
cloud.google.com/appengine/downloads.
Open Terminal and unzip the downloaded zip file to your home directory:
cd ~ unzip ~/Downloads/go_appengine_sdk*.zip
This should create a go_appengine
folder in your home
directory. The App Engine SDK is self-contained and requires no
installation. If you want to remove it just delete the folder.
Environment variables are key-value pairs that any program you execute has access to. They are used as form of configuration that makes programs more flexible.
We need to configure two environment variables: PATH
and
GOPATH
. PATH
is used by the operating system
to locate executables. It's what makes it possible to execute
go version
instead of /usr/local/go/bin/go version
.
GOPATH
is used by the Go compiler to find go source code.
Open a terminal and run the following:
env GOPATH=$HOME go get github.com/badgerodon/penv/...
This installs an executable named penv
which we can use to
set environment variables. To update PATH
run this:
$HOME/bin/penv append PATH $HOME/bin $HOME/bin/penv append PATH $HOME/go_appengine
To update the GOPATH
run this:
$HOME/bin/penv set GOPATH $HOME
Finally make sure to quit the Terminal. (So it will pick up the changes)
You should now have everything you need to create applications with Go and Google App Engine. To verify that your Go installation works open a terminal and run the following:
go get github.com/k0kubun/tetris ; tetris
And you can play tetris. Type q
to exit.
Git is a version control system. We need it for two reasons: (1) many components of Go are distributed via Git and (2) the Windows installer includes a terminal that makes it behave more like Unix operating systems (like OSX or Linux).
Download and install msysgit from msysgit.github.io. When the installer asks make sure to select "Use Git from the Windows Command Prompt".
Windows comes with a terminal called cmd.exe
. You can start
it by click Start and typing cmd
and then selecting it:
Go ahead and close it as we will be using a different terminal that comes bundled with msysgit. Click Start -> All Programs -> Git -> Git Bash.
Terminals are a text-driven interface to your computer. You can enter commands by typing the command and hitting enter. Your computer will then execute the command and display any results.
Terminals also allow you to manipulate files and folders on your computer.
You terminal starts in a working directory
where you can list
the folder contents with ls
, change directories using
cd
, make directories using mkdir
and remove
files using rm
.
GitHub's Atom is powerful text editor which we will use it to create Go source code files. Download and install it from atom.io.
We also need to install a more robust Go plugin. In Atom go to File ->
Settings. Then select Install, and type go-plus
into the search
box. Install the plugin named go-plus
:
Once that is complete, go ahead and close Atom.
Go is a compiled programming language so we need to install the Go toolset. Download and run the installer from here: golang.org/dl. Choose windows-amd64.msi for 64 bit or windows-386.msi for 32 bit. (you probably want the 64 bit version)
Confirm that it worked by opening a new terminal and typing:
go version
You should see the go version you installed.
Google's App Engine is a managed platform for web applications. If you aren't interested in installing App Engine you can skip this step.
Install the Google Cloud Tools
from:
https://cloud.google.com/sdk/docs/#windows.
After installation, open a bash terminal and install the app engine component:
gcloud components install app-engine-go
Python is required for App Engine. If you skipped App Engine you can also skip this step.
Download python 2.7 from python.org/downloads and install it.
Important: Make sure to install Python 2.X and not Python 3.X.
Environment variables are key-value pairs that any program you execute has access to. They are used as form of configuration that makes programs more flexible.
We need to configure two environment variables: PATH
is
used by the operating system to locate executables. It's what makes it
possible to execute go version
instead of
/c/Go/bin/go version
. GOPATH
is used by the
Go compiler to find go source code.
Open a bash terminal and run the following:
GOPATH=$HOME go get github.com/badgerodon/penv/...
This installs an executable named penv.exe
we can use to
set environment variables. To update the PATH
run this:
$HOME/bin/penv append PATH $HOME/bin $HOME/bin/penv append PATH $HOME/go_appengine
To update the GOPATH
run this:
$HOME/bin/penv set GOPATH $HOME
Close the terminal.
You should now have everything you need to create Go programs. To confirm this run the following in a new bash terminal:
go get github.com/k0kubun/tetris ; tetris
A tetris game should start. Type q to exit.
For chromebooks or other operating systems we can use Nitrous.io as a cloud-based programming environment.
Go to lite.nitrous.io and create a new account. Login and create a new box. Choose Go as the template and US West as the region (or whatever you prefer).
Wait a bit and your new machine should bootup. The Nitrous IDE comes with many of the tools we would normally need to configure preinstalled. This includes a basic text editor, the terminal (Console) and Git.
Nitrous.io has the Go toolchain pre-installed, but it's an out of date version. Run the following to update it:
parts update ; parts install go
Google's App Engine is a managed platform for web applications. If you aren't interested in installing App Engine you can skip this step.
Download the Google App Engine SDK for Go
from
cloud.google.com/appengine/downloads
using this command: (enter this in the Console at the bottom of the screen)
cd ~ curl -O https://storage.googleapis.com/appengine-sdks/featured/go_appengine_sdk_linux_amd64-1.9.21.zip
curl
is a command line application which can make http
requests like your web browser does. In this case we use it to download
the zip file.
Once that completes, unzip the SDK by running this:
cd ~ unzip ~/go_appengine_sdk*.zip
This should create a go_appengine
folder in your home
directory. The App Engine SDK is self-contained and requires no installation.
If you want to remove it just delete the folder.
Environment variables are key-value pairs that any program you execute has access to. They are used as form of configuration that makes programs more flexible.
We need to configure two environment variables: PATH
and
GOPATH
. PATH
is used by the operating system
to locate executables. It's what makes it possible to execute
go version
instead of /usr/local/go/bin/go version
.
GOPATH
is used by the Go compiler to find go source code.
Open a terminal and run the following:
env GOPATH=$HOME go get github.com/badgerodon/penv/...
This installs an executable named penv
which we can use to
set environment variables. To update PATH
run this:
$HOME/bin/penv append PATH $HOME/bin $HOME/bin/penv append PATH $HOME/go_appengine
To update the GOPATH
run this:
$HOME/bin/penv set GOPATH $HOME
Finally make sure to close the Console. (So when re-opened it will pick up the changes)
You should now have everything you need to create applications with Go and Google App Engine. To verify that your Go installation works open a terminal and run the following:
go get github.com/k0kubun/tetris ; tetris
And you can play tetris. Type q
to exit.