Installing Go from source

1. Introduction

Go is a nice language started by Google. A nice advantage is that it compiles to native code and the binary does not have additional dependencies. Performance and low resource usage are focused on, even though I personally don't like the gargabe collection based memory cleanup.

Go brings very good documentation (godoc for accessing it), and it enforces a well defined code formatting (gofmt).

Even for Emacs the supporting tools are great, including very good code completion and documentation access which makes it nice to develop in Go.

The compiler itself used to be very fast (in Go 1.4) but got somewhat slower in newer version. But it is still fast enough in contrast to other language, especially since it can build whole project without additional tools.

Finally, it is easy to include third-party projects with "go get" which downloads packages and stores them locally (which you might want to store in case the remote repository is longer available in a year or so).

2. Installation

Since Go version 1.5 you need Go itself to compile it. So we first start with Go 1.4:
  1. Download it from https://golang.org/doc/install/source?download=go1.4.3.src.tar.gz
  2. Untar it, let's assume the directory is DIR14
  3. cd to "DIR14/src"
  4. Build Go 1.4 with:
    ./all.bash
    
After some minutes you have a working Go 1.4 installation. Now let's progress to the current version:
  1. Download Go 1.6 from https://golang.org/doc/install/source?download=go1.6.2.src.tar.gz
  2. Untar to DIR16, let's assume the directory is DIR16
  3. cd to "DIR16/src"
  4. Tell Go where to find the Go compiler to bootstrap with:
    export GOROOT_BOOTSTRAP=DIR14
    
  5. Now build Go 1.6 with :
    ./all.bash
    
After some more minutes, you finally have working Go 1.6 installation. You can set some environment variables in your .bashrc to have everything prepared for development:
  1. Set the root of the Go installation:
    export GOROOT=DIR16
    
  2. Tell go where to store additional packages downloaded with "go get":
    export GOPATH=<path/to/addons>
    
  3. And finally add the bin directory to your PATH:
    export PATH=$PATH:$GOROOT/bin
    
You can install the godoc tool with:
go get golang.org/x/tools/cmd/godoc
or install all tools with
go get golang.org/x/tools/cmd/...

3. Test compiler

  1. Create a file "hello.go" with content
    package main
    import "fmt"
    func main() {
            fmt.Println("Hello World")
    }
    
  2. Compile with
    go build hello.go
    
  3. Run with
    ./hello