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.
11 Answers
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
/bin/bash -c "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Now Install jq
brew install jq
4 Comments
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/jqlang/jq/wiki/Installation
The same page also includes details regarding installation from source, and has notes on installing with MacPorts ("ports"), asdf (asdf-vm), and 0install ("zero-install").
Footnote: one can also use brew to install the Go and Rust implementations of jq:
brew install gojq
brew install jaq
5 Comments
error: [Errno 2] No such file or directory ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/bk/qxg2q6ss39g1ft4470j34tzh0000gn/T/pip-build-AEc_pb/jq/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/bk/qxg2q6ss39g1ft4470j34tzh0000gn/T/pip-utaZJq-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/bk/qxg2q6ss39g1ft4470j34tzh0000gn/T/pip-build-AEc_pb/jq/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"
}
Comments
Check if homebrew is installed
brew install jq
1 Comment
Warning: No available formula with the name "jq". and some other errors.The question is very old but here's an update for the current macOS version. macOS Sequoia (15) has jq commnand-line utility pre-installed with the operating system. Xcode command line developer tools package isn't needed.
$ which jq
/usr/bin/jq
$ jq --version
jq-1.6-159-apple-gcff5336-dirty
Comments
Install jq without brew (Debian-based Linux):
sudo apt install jq- Check the version for successful installation:
jq --version
Install jq without brew (Mac):
Download the jq file:
curl -L -o jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64orwget -O jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64Make the file executable:
chmod +x jqMove the file to a directory in your PATH:
sudo mv jq /usr/local/binCheck the version for successful installation:
jq --version
Comments
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.
1 Comment
brew does the trick, providing questionable value after the first?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
2 Comments
pip install jq doesn't install jq itself; it only installs a Python wrapper for jq.
brew?