install multiple versions of GO on the same machine [linux]

This quick tutorial shows how to do install multiple versions of go manually.

I’ll try to prepare a shell script that will do it automatically for you 🙂

  1. download selected GO releases
  2. create directories for specific version of GO
  3. unpack downloaded GO releases
  4. install `go` alternatives
  5. install `godoc` alternatives
  6. install `gofmt` alternatives
  7. configure version of go, godoc & gofmt interactively
  8. alternatively you can configured it in a non-interactive way
  9. set the GOROOT env variable to match the location of selected version of GO
# 1
wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
wget https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz
wget https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz
wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz

# 2
sudo mkdir -p /usr/local/go/1.4.2/
sudo mkdir -p /usr/local/go/1.4.3/
sudo mkdir -p /usr/local/go/1.5/
sudo mkdir -p /usr/local/go/1.5.1/

# 3
sudo tar -C /usr/local/go/1.4.2/ --strip-components=1 -xzf go1.4.2.linux-amd64.tar.gz
sudo tar -C /usr/local/go/1.4.3/ --strip-components=1 -xzf go1.4.3.linux-amd64.tar.gz
sudo tar -C /usr/local/go/1.5/ --strip-components=1 -xzf go1.5.linux-amd64.tar.gz
sudo tar -C /usr/local/go/1.5.1/ --strip-components=1 -xzf go1.5.1.linux-amd64.tar.gz

# 4
sudo update-alternatives --install /usr/bin/go go /usr/local/go/1.4.2/bin/go 2
sudo update-alternatives --install /usr/bin/go go /usr/local/go/1.4.3/bin/go 3
sudo update-alternatives --install /usr/bin/go go /usr/local/go/1.5/bin/go 4
sudo update-alternatives --install /usr/bin/go go /usr/local/go/1.5.1/bin/go 5

# 5
sudo update-alternatives --install /usr/bin/godoc godoc /usr/local/go/1.4.2/bin/godoc 2
sudo update-alternatives --install /usr/bin/godoc godoc /usr/local/go/1.4.3/bin/godoc 3
sudo update-alternatives --install /usr/bin/godoc godoc /usr/local/go/1.5/bin/godoc 4
sudo update-alternatives --install /usr/bin/godoc godoc /usr/local/go/1.5.1/bin/godoc 5

# 6
sudo update-alternatives --install /usr/bin/gofmt gofmt /usr/local/go/1.4.2/bin/gofmt 2
sudo update-alternatives --install /usr/bin/gofmt gofmt /usr/local/go/1.4.3/bin/gofmt 3
sudo update-alternatives --install /usr/bin/gofmt gofmt /usr/local/go/1.5/bin/gofmt 4
sudo update-alternatives --install /usr/bin/gofmt gofmt /usr/local/go/1.5.1/bin/gofmt 5

# 7 - If you want to configure version of go, godoc & gofmt interactively then use:
sudo update-alternatives --config go
sudo update-alternatives --config godoc
sudo update-alternatives --config gofmt

# 8 - If you want to configure version non-interactively then use:
sudo update-alternatives --set go /usr/local/go/1.4.2/bin/go
sudo update-alternatives --set godoc /usr/local/go/1.4.2/bin/godoc
sudo update-alternatives --set gofmt /usr/local/go/1.4.2/bin/gofmt

sudo update-alternatives --set go /usr/local/go/1.4.3/bin/go
sudo update-alternatives --set godoc /usr/local/go/1.4.3/bin/godoc
sudo update-alternatives --set gofmt /usr/local/go/1.4.3/bin/gofmt

sudo update-alternatives --set go /usr/local/go/1.5/bin/go
sudo update-alternatives --set godoc /usr/local/go/1.5/bin/godoc
sudo update-alternatives --set gofmt /usr/local/go/1.5/bin/gofmt

sudo update-alternatives --set go /usr/local/go/1.5.1/bin/go
sudo update-alternatives --set godoc /usr/local/go/1.5.1/bin/godoc
sudo update-alternatives --set gofmt /usr/local/go/1.5.1/bin/gofmt

# 9 - set GOROOT to your current version of GO
export GOROOT=$(dirname $(dirname $(readlink -f $(which go | cut -d" " -f3))))

How to selectively run, in jBehave, stories tagged with multiple words in a meta field.

Prerequisites:
1) a working jBehave based project
This short tutorial is based on an jbehave-tutorial project available on github: https://github.com/jbehave/jbehave-tutorial.
To be precise I used the “java-spring” submodule from the “etsy-selenium” module, available here: https://github.com/jbehave/jbehave-tutorial/tree/master/etsy-selenium/java-spring, to run the modified story presented below.
2) Maven

OK, let’s consider a situation when we have stories belonging to multiple features, categories etc.
Below is an example story, tagged with multiple categories and features:

anExampleStoryWithMultipleWordsInAMetaKeyword.story

Meta:
@categories category1 category2 category3
@features feature1 feature2 feature3 feature_4

Scenario: scenario description
Given I'm on the homepage
....

Now, we’d like to run stories only for a selected category or a feature.
To accomplish this we’ll use the value pattern matching mechanism implemented in the jBehave meta matcher and described here.

Examples:
Run stories covering only category3:

mvn clean install -Dmeta.filter="+categories *category3*"

Run stories covering only feature_4:

mvn clean install -Dmeta.filter="+features *feature_4*"

And finally, run stories matching feature2 and category1:

mvn clean install -Dmeta.filter="+features *feature2* +categories *category1*"

Notice:
It seems that jBehave is not handling “-” hyphens in the keyword value properly, but it works fine with “_” underscores, separate words and camelCase notation 🙂