How to install JQ on Mac on the command line?

JsonMacosCommand LineInstallationJq

Json Problem Overview


I need to know the most efficient way of installing JQ on Mac (El Capitan). The code is downloaded to my Mac but I would like to know how I can install and operate it via the command line.

Json Solutions


Solution 1 - Json

You can install any application/packages with brew on mac. If you want to know the exact command just search your package on https://brewinstall.org and you will get the set of commands needed to install that package.

First open terminal and install brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

Now Install jq

brew install jq

Solution 2 - Json

On a Mac, the "most efficient" way to install jq would probably be using homebrew, e.g.

brew install jq

If you want the development version, you could try:

brew install --HEAD jq

but this has various pre-requisites.

Detailed instructions are on the "Installation" page of the jq wiki: https://github.com/stedolan/jq/wiki/Installation

The same page also includes details regarding installation from source, and has notes on installing with MacPorts ("ports"), asdf ([tag:asdf-vm]), and 0install ("zero-install").

Solution 3 - Json

The simplest way to install jq and test that it works is through brew and then using the simplest filter that merely formats the JSON

Install

brew is the easiest way to manage packages on a mac:

brew install jq

Need brew? Run the following command:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Failing that: instructions to install and use are on https://brew.sh/

Test

The . filter takes its input and produces it unchanged as output. This is the identity operator. (quote the docs)

echo '{ "name":"John", "age":31, "city":"New York" }' | jq .

The result should appear like so in your terminal:

{
  "name": "John",
  "age": 31,
  "city": "New York"
}

Solution 4 - Json

To make sure homebrew is installed and install jq

git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow 
brew update
brew install jq

Solution 5 - Json

For most it is a breeze, however like you I had a difficult time installing jq

The best resources I found are: https://stedolan.github.io/jq/download/ and http://macappstore.org/jq/

However neither worked for me. I run python 2 & 3, and use brew in addition to pip, as well as Jupyter. I was only successful after brew uninstall jq then updating brew and rebooting my system

What worked for me was removing all previous installs then pip install jq

Solution 6 - Json

For CentOS, RHEL, Amazon Linux: sudo yum install jq

Solution 7 - Json

Check if homebrew is installed

brew install jq

Solution 8 - Json

If you are looking for a good alternative to homebrew (whether in a Mac or Linux environment), one such is 0install ("Zero Install"), which indeed has some advantages. For example, it's trivially easy to have multiple versions of jq installed together.

If you already have 0install installed, to add jq it would be sufficient to type:

0install add jq https://apps.0install.net/utils/jq.xml

This installs a tiny script in ~/bin/jq, which you can use as though it were jq itself.

To install a particular version of jq, say jq 1.5, you just have to specify the version number:

0install add --version=1.5 jq1.5 https://apps.0install.net/utils/jq.xml

Further details about the versions of jq that are available using this "feed" for 0install can be obtained by viewing the above-mentioned URL in a browser.

Installing 0install

One option for installing 0install itself would of course be:

 brew install 0install

Currently, a better option is to run:

curl -O https://get.0install.net/0install.sh && chmod +x 0install.sh
./0install.sh

and then follow the directions.

See 0install.net for further details.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRoss BranniganView Question on Stackoverflow
Solution 1 - JsonAjeet KhanView Answer on Stackoverflow
Solution 2 - JsonpeakView Answer on Stackoverflow
Solution 3 - JsonStefan CollierView Answer on Stackoverflow
Solution 4 - JsonstevecView Answer on Stackoverflow
Solution 5 - JsonAntoineView Answer on Stackoverflow
Solution 6 - JsonMohammad Selim MiahView Answer on Stackoverflow
Solution 7 - JsonAbhishek KhaiwaleView Answer on Stackoverflow
Solution 8 - JsonpeakView Answer on Stackoverflow