'How to install JQ on Mac on the command line?
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.
Solution 1:[1]
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:[2]
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 (asdf-vm), and 0install ("zero-install").
Solution 3:[3]
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:[4]
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:[5]
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:[6]
For CentOS, RHEL, Amazon Linux: sudo yum install jq
Solution 7:[7]
Check if homebrew is installed
brew install jq
Solution 8:[8]
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.
Solution 9:[9]
Nothing agaist brew (I use both) but if you want to you can use macports
sudo port install jq
FWIW, jc's an interesting utility that plays very well with jq (its purpose is to json-ize command outputs). And, yes, brew install jc
or sudo port install jc
both work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ajeet Khan |
Solution 2 | |
Solution 3 | |
Solution 4 | stevec |
Solution 5 | Antoine |
Solution 6 | Mohammad Selim Miah |
Solution 7 | Abhishek Khaiwale |
Solution 8 | peak |
Solution 9 |