Installing jq from Source

Packages built in both Ubuntu and Debian packages lack behind, therefore, to get the latest version of jq, build from source.

There are a few prerequisites to install:

  • GCC
  • Make
  • Autotools

Both GCC and Make are usually installed if you do development, but not Autotools. Luckily, this is easy to fulfill:

1
$ sudo apt-get install automake

Install from source:

1
2
3
4
$ sudo git clone https://github.com/stedolan/jq.git
$ cd jq
$ sudo git checkout jq-1.5
$ sudo ./configure && sudo make && sudo make install

The installed path is at:

1
2
$ which jq
jq is /usr/local/bin/jq

However, this gives me an unexpected tag:

1
2
$ jq --version
jq-1.5-dirty

I have no idea why there is dirty suffix, did a quick search, saw the same tag referenced in this issue: https://github.com/stedolan/jq/issues/916, but yet to have answer for it. I might be using the wrong commit, but instead of searching and figuring out why, sometimes it’s easier to take the different road, if your goal is not to debug. So, went ahead and just downloaded the tarball:

1
2
3
4
$ wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-1.5.tar.gz
$ tar xzf jq-1.5.tar.gz
$ cd jq-1.5/
$ sudo ./configure && sudo make && sudo make install

Now it looks to be something I want:

1
2
$ jq --version
jq-1.5

Try an example:

1
2
3
4
$ echo '{"foo":"bar"}' | jq .
{
"foo": "bar"
}

So far so good. For more information, see https://stedolan.github.io/jq/download/.