I recently had to install GitVersion on an Ubuntu 16.04 server as part of provisioning a new build agent. I had to spend a bit of time figuring out how to do this, primarily due to the fragmented documentation. Hopefully these steps, all in one place, can help save others time.

Step 1 - Install Mono + Dependencies

GitVersion is written in C# .NET and as such requires the Mono framework in order to run on Linux.

Install Mono:

$ sudo apt-get install mono-complete

GitVersion also requires libcurl3:

$ sudo apt-get install libcurl3

Step 2 - Download GitVersion

Download the latest release from GitHub:

$ wget https://github.com/GitTools/GitVersion/releases/download/v4.0.0-beta.12/GitVersion_4.0.0-beta0012.zip

Unzip it to a new folder:

$ unzip GitVersion_4.0.0-beta0012.zip -d GitVersion

Step 3 - Install GitVersion

At this point you should be able to run:

$ mono GitVersion/GitVersion.exe

However, it will error as it is not being executed from inside a git repository. In order to execute GitVersion in any folder we choose we need to add it to the path.

Step 3.1 - Create GitVersion Wrapper

To make usage simple we will create a wrapper for GitVersion so that we can call it like any other standard Linux command.

First, change into the GitVersion folder:

$ cd GitVersion

Print the current working directory and then copy its value to your clipboard:

$ pwd

Open a new file using your text editor:

$ nano gitversion

Type or paste the following lines into the new file, substituting current_working_directory with the contents of the pwd command you previously copied.

mono {current_working_directory}/GitVersion.exe "[email protected]"

Save the file and exit.

Step 3.2 - Add GitVersion to the /usr/sbin

The final step in the install process is to add our wrapper to the /usr/local/bin folder. This will allow us to execute gitversion from any folder.

To add the wrapper to /usr/local/bin create a symlink:

$ ln -S $(pwd)/gitversion /usr/local/bin/gitversion

Make sure to run the above command in the GitVersion folder previously created to ensure the symlink is created with the correct path.

Step 4 - Using the command

GitVersion should now be installed! To use it you simply execute gitversion from within a git repository, passing any parameters you wish. Full docs on usage can be found here.