How to install JQ on Mac on the command line? - json

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.

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

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").
Footnote: one can also use brew to install the Go implementation of jq:
brew install gojq

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"
}

Check if homebrew is installed
brew install jq

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

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

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

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.

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.

install jq without brew:
sudo apt install jq

Related

Error while installing json gem 'mkmf.rb can't find header files for ruby'

For context, it on a remote server which has a firewall. I'm setting up my environment through a proxy. I have ruby 1.8.7. When I try to gem install..
sudo gem install --http-proxy <host address>:<port> json
I get the following error:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/json-1.8.1 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
Since I was unsure what the problem is, I googled and found these
gem install: Failed to build gem native extension (can't find header files) - the instructions here seem to be specific to the gem being installed.
How to install json gem - Failed to build gem native extension This seems to be slightly different error.
Any hints? Thanks!
Modern era update, as stated by mimoralea:
In case that you are using ruby 2.0 or 2.2 (thanks #patrick-davey).
sudo apt-get install ruby2.0-dev
sudo apt-get install ruby2.2-dev
sudo apt-get install ruby2.3-dev
or, generic way:
sudo apt-get install ruby-dev
or
sudo apt-get install ruby`ruby -e 'puts RUBY_VERSION[/\d+\.\d+/]'`-dev
The first link you’ve posted is exactly your case: there is no ruby development environment installed. Development env is needed to compile ruby extensions, which are mostly written in C. Proxy has nothing to do with the problem: everything is downloaded fine, just compilation fails.
I would suggest you to install ruby-dev (ruby-devel for rpm-based distros) package onto you target machine.
gcc package might be needed as well.
Try:
$ sudo apt-get install ruby-dev
Or, for Redhat distro:
$ sudo yum install ruby-devel
Or, for [open]SuSE:
$ sudo zypper install ruby-devel
For Xcode 11 on macOS 10.14, this can happen even after installing Xcode and installing command-line tools and accepting the license with
sudo xcode-select --install
sudo xcodebuild -license accept
The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14's ruby2.3. You can verify that this is your problem by running
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
which on macOS 10.14 with Xcode 11 prints the non-existent path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
However, Xcode 11 installs a macOS 10.14 SDK within /Library/Developer/CommandLineTools/SDKs/MacOS10.14.sdk. It isn't necessary to pollute the system directories by installing the old header files as suggested in other answers. Instead, by selecting that SDK, the appropriate ruby2.3 headers will be found:
sudo xcode-select --switch /Library/Developer/CommandLineTools
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
This should now correctly print
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
Likewise, gem install should work while that SDK is selected.
To switch back to the current Xcode SDK, use
sudo xcode-select --switch /Applications/Xcode.app
In case that you are using ruby 2.0 or 2.2 (thanks #patrick-davey) or 2.3 (thanks #juanitofatas).
sudo apt-get install ruby-dev
sudo apt-get install ruby2.0-dev
sudo apt-get install ruby2.2-dev
sudo apt-get install ruby2.3-dev
And you get the pattern here...
I also encountered this problem because I install Ruby on Ubuntu via brightbox, and I thought ruby-dev is the trunk of ruby. So I did not install. Install ruby2.3-dev fixes it:
sudo apt-get install ruby2.3-dev
For those who are getting this on Mac OS X you may need to run the following command to install the XCode command-line tools, even if you already have XCode installed:
sudo xcode-select --install
Also you must agree the terms and conditions of XCode by running the following command:
sudo xcodebuild -license
I had a similar problem using cygwin to run the following command:
$ gem install rerun
I solved it by installing the following cygwin packages:
ruby-devel
libffi-devel
gcc-core
gcc-g++
make
automake1.15
Most voted solution didn't work on my machine (linux mint 18.04).
After a careful look, i found that g++ was missing.
Solved with
sudo apt-get install g++
in case you use SUSE
sudo yast2 -i ruby-devel
Xcode 11 / macOS Catalina
On Xcode 11 / macOS Catalina, the header files are no longer in the old location and the old /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg file is no longer available.
Instead, the headers are now installed to the /usr/include directory of the current SDK path:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
Most of this directory can be found by using the output of xcrun --show-sdk-path. And if you add this path to the CPATH environment variable, then build scripts (including those called via bundle) will generally be able to find it.
I resolved this by setting my CPATH in my .zshrc file:
export CPATH="$(xcrun --show-sdk-path)/usr/include"
After opening a new shell (or running source .zshrc), I no longer receive the error message mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h and the rubygems install properly.
Note on Building to Non-macOS Platforms
If you are building to non-macOS platforms, such as iOS/tvOS/watchOS, this change will attempt to include the macOS SDK in those platforms, causing build errors. To resolve, either don't set CPATH environment variable on login, or temporarily set it to blank when running xcodebuild like so:
CPATH="" xcodebuild --some-args
In Fedora 21 and up, you simply open a terminal and install the Ruby Development files as root.
dnf install ruby-devel
On Mac 10.14, the header files don't seem to be installed in the correct place. Rather than changing paths like the other fixes, I was able to just run this:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Follow the instructions and it resolved this problem for me.
You may need to install gcc after install ruby-devel
Xcode -> Preferences -> Locations
change Command Line Tools to Xcode 11.2.1
You need to install the entire ruby and not just the minimum package. The correct command to use is:
sudo apt install ruby-full
The following command will also not install a complete ruby:
sudo apt-get install ruby2.3-dev
For Ubuntu 18, after checking log file mentioned while install
Results logged to /var/canvas/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/nio4r-2.5.2/gem_make.out
with
less /var/canvas/vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0/nio4r-2.5.2/gem_make.out
I noticed that make is not found. So installed make by
sudo apt-get install make
everything worked.
I faced a similar issue on Xcode 12 with macOS 10.15 and cocoapods. Just make sure that the xcode-select command points to the SDK you want to build against. It should build without issues afterwards.
BEFORE you follow the tip from Joki's answer (below) and IF :
you have MacOS 10.14.6
at /Library/Developer/CommandLineTools/SDKs/ you have folders
MacOSX.sdk(symbolic), MacOSX10.14.sdk, MacOSX10.15.sdk
Move MacOSX10.15.sdk to anywhere (admin privileges needs)
Delete symbolic link (admin privileges needs)
At /Library/Developer/CommandLineTools/SDKs/ create another symbolic link now to MacOSX10.14.sdk folder using (admin privileges needs)
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk MacOSX.sdk
Now you can follow Joki's answer
WARNING!
If you move MacOSX10.15.sdk folder to /Library/Developer/CommandLineTools/SDKs/ again, the command
ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
will show MacOSX10.15.sdk folder like default again, nowadays I dunno how to fix it! My suggestion, compress the folder and put the original folder until fix will be available.
macOS RubyMine Gem installation failure
My problem with this error message was when trying to install a Gem via RubyMine. It didn't like that I had changed the global Ruby version with rbenv, so I fixed it by changing back to the system default Ruby version with:
rbenv global system
and restarted RubyMine.
sudo apt-get --reinstall install ruby
try it for ubuntu 16.04

How to download all dependencies and packages to directory

I'm trying to install a package on a machine with no Internet connection. What I want to do is download all the packages and dependences on a machine WITH an Internet connection and then sneaker-net everything to the offline computer.
I've been playing with the apt-get and apt-cache but I haven't figured out a quick and easy way to download the package and dependencies in one swoop to a directory of my choosing. How would I do this? Am I going about this problem correctly?
How would you install offline packages that have a lot of dependencies?
The marked answer has the problem that the available packages on the machine that is doing the downloads might be different from the target machine, and thus the package set might be incomplete.
To avoid this and get all dependencies, use the following:
apt-get download $(apt-rdepends <package>|grep -v "^ ")
Some packages returned from apt-rdepends don't exist with the exact name for apt-get download to download (for example, libc-dev). In those cases, filter out those exact names (be sure to use ^<NAME>$ so that other related names, for example libc-dev-bin, that do exist are not skipped).
apt-get download $(apt-rdepends <package>|grep -v "^ " |grep -v "^libc-dev$")
Once downloaded, you can move the .deb files to a machine without Internet and install them:
sudo dpkg -i *.deb
Same question already answered here:
How to list/download the recursive dependencies of a debian package?
try:
PACKAGES="wget unzip"
apt-get download $(apt-cache depends --recurse --no-recommends --no-suggests \
--no-conflicts --no-breaks --no-replaces --no-enhances \
--no-pre-depends ${PACKAGES} | grep "^\w")
# aptitude clean
# aptitude --download-only install <your_package_here>
# cp /var/cache/apt/archives/*.deb <your_directory_here>
The aptitude --download-only ... approach only works if you have a debian distro with internet connection in your hands.
If you don't, I think it is better to run the following script on the disconnected debian machine:
apt-get --print-uris --yes install <my_package_name> | grep ^\' | cut -d\' -f2 >downloads.list
move the downloads.list file into a connected linux (or non linux) machine, and run:
wget --input-file myurilist
this downloads all your files into the current directory.After that you can copy them on an USB key and install in your disconnected debian machine.
Credits: http://www.tuxradar.com/answers/517
This will download all the Debs to the current directory, and will NOT fail if It can't find a candidate.
Also does NOT require sudo to run sript!
nano getdebs.sh && chmod +x getdebs.sh && ./getdebs.sh
#!/bin/bash
package=ssmtp
apt-cache depends "$package" | grep Depends: >> deb.list
sed -i -e 's/[<>|:]//g' deb.list
sed -i -e 's/Depends//g' deb.list
sed -i -e 's/ //g' deb.list
filename="deb.list"
while read -r line
do
name="$line"
apt-get download "$name"
done < "$filename"
apt-get download "$package"
Note: I used this as my example because I was actually trying to DL the Deps for SSMTP and it failed on debconf-2.0, but this script got me what I need!
Somewhat simplified (and what worked for me) way that worked for me (based on all the above)
Note that dependencies hierarchy can go deeper then one level
Get dependencies of your package
$ apt-cache depends mongodb | grep Depends:
Depends: mongodb-dev
Depends: mongodb-server
Get urls:
sudo apt-get --print-uris --yes -d --reinstall install mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-tools | grep "http://" | awk '{print$1}' | xargs -I'{}' echo {} | tee files.list
wget --input-file files.list
I used apt-cache depends package to get all required packages in any case if the are already installed on system or not.
So it will work always correct.
Because the command apt-cache works different, depending on language, you have to try this command on your system and adapt the command.
apt-cache depends yourpackage
On an englisch system you get:
$ apt-cache depends yourpackage
node
Depends: libax25
Depends: libc6
On an german system you get:
node
Hängt ab von: libax25
Hängt ab von: libc6
The englisch version with the term:
"Depends:"
You have to change the term "yourpackage" to your wish twice in this command, take care of this!
$ sudo apt-get --print-uris --yes -d --reinstall install yourpackage $(apt-cache depends yourpackage | grep " Depends:" | sed 's/ Depends://' | sed ':a;N;$!ba;s/\n//g') | grep ^\' | cut -d\' -f2 >downloads.list
And the german version with the term:
"Hängt ab von:"
You have to change the term "yourpackage" to your wish twice in this command, take care of this!
This text is used twice in this command, if you want to adapt it to your language take care of this!
$ sudo apt-get --print-uris --yes -d --reinstall install yourpackage $(apt-cache depends yourpackage | grep "Hängt ab von:" | sed 's/ Hängt ab von://' | sed ':a;N;$!ba;s/\n//g') | grep ^\' | cut -d\' -f2 >downloads.list
You get the list of links in downloads.list
Check the list, go to your folder and run the list:
$ cd yourpathToYourFolder
$ wget --input-file downloads.list
All your required packages are in:
$ ls yourpathToYourFolder
This will download all packages and dependencies (no already installed) to a directory of your choice:
sudo apt-get install -d -o Dir::Cache=/path-to/directory/apt/cache -o Dir::State::Lists=/path-to/directory/apt/lists packages
Make sure /path-to/directory/apt/cache and /path-to/directory/apt/lists exist.
If you don't set -o Dir::Cache it points to /var/cache/apt,
Dir::State::Lists points to /var/lib/apt/lists (which keeps the index files of available packages)
Both -o options can be used with update and upgrade instead of install.
On different machine run the same command without '-d'
I'm assuming you've got a nice fat USB HD and a good connection to the net. You can use apt-mirror to essentially create your own debian mirror.
http://apt-mirror.sourceforge.net/
On modern Ubuntu systems (for example, 22.04):
apt clean
apt update
apt install --download-only freeipa-client
After you can find deb-files in
ls -l /var/cache/apt/archives/
IF you accept the caveat that there may be dependencies already installed on your system, then the easiest way is to go apt-get install --simulate <your_package>, this will first list all the deps it will install, then copy the list of packages, then apt-get download <the_list_of_packages>
e.g. for qt5-gtk2-platformtheme on a xubuntu-21.04 MINIMAL INSTALL you'll get (after apt-get install --simulate) the following:
libdouble-conversion3 libmd4c0 libpcre2-16-0 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5widgets5 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-render-util0 libxcb-xinerama0 libxcb-xinput0 libxcb-xkb1 libxkbcommon-x11-0 qt5-gtk-platformtheme qttranslations5-l10n
then you just cd in a folder of your choice, do apt-get download <the_list_above>, and you have them all d/w in there. you can then dpkg -i *.deb
Complementing and automating the exclusion of ALL conflictive dependencies (dependencies not found) by the command given by #onno:
apt-get download $(apt-rdepends <package>|grep -v "^ " |grep -v "^conflictiv-dependency$")
At least for Ubuntu, where the Error Message format is as follows:
E: Can't select candidate version from package <package> as it has no candidate
The following script Downloads all Found Dependencies, Excluding not Found ones:
#!/bin/bash
rm -f error.txt
apt download $(apt-rdepends $1 | grep -v "^ ") 2> error.txt
#IF THERE WAS ERRORS (DEPENDENCIES NOT FOUND)
if [ $(cat error.txt | wc -l) -gt 0 ]
then
partial_command="\("
while read -r line
do
conflictive_package="$(awk '{split($0,array," "); print array[8]}' <<< $line)"
partial_command="$partial_command$conflictive_package\|"
done < error.txt
partial_command="$(awk '{print substr($0, 1, length($0)-2)}' <<< $partial_command)\)"
eval "apt download \$(apt-rdepends $1 | grep -v '^ ' | grep -v '^$partial_command$')"
fi
rm error.txt
It works with me
sudo apt-get reinstall --download-only <your software>
for example
sudo apt-get reinstall --download-only ubuntu-restricted-extras
For accessing installed .deb files, you can look in this path:
/var/cache/apt/archives

Install perl-JSON on centos

When I'm trying to run a perl script (on my centos 6 machine) I get this message:
Can't locate JSON.pm in #INC (#INC contains:
/usr/local/lib/perl5/5.10.1/x86_64-linux-thread-multi
/usr/local/lib/perl5/5.10.1
/usr/local/lib/perl5/site_perl/5.10.1/x86_64-linux-thread-multi
/usr/local/lib/perl5/site_perl/5.10.1 .)...
After googling a bit, I found out that I need to install that module; But, when I'm typing:
sudo yum install perl-JSON
I get this message:
...
Setting up Install Process
Package perl-JSON-2.17-1.el5.noarch already installed and latest version
Nothing to do
What can I do in order to run that script?
My perl version is v5.10.1
Thanks,
Try to install it via:
1) CPAN (cpan install)
$ sudo cpan JSON
2) CPAN minus (cpanm)
Install cpan minus
$ wget http://search.cpan.org/CPAN/authors/id/M/MI/MIYAGAWA/App-cpanminus-1.5017.tar.gz
$ tar -zxvf App-cpanminus-1.5017.tar.gz
$ cd App-cpanminus-1.5017
$ perl make.pl
$ make
$ make test
$ sudo make install
Then install it via cpanm
$ sudo cpanm JSON
I prefer work with CPAN modules via cpanm, because it's modern and easy way!
Maybe this will help others.
In my case,
running in Centos 7:
yum install cpan
then
yum install cpanminus
for cpan (not cpan minus):
yum install cpan
cpan JSON

cannot find -lmysqlclient

I'm trying to compile a C++ program and one of the classes uses . g++ is not able to find the libraries would be my guess. The command i use to compile is -
g++ c1.cpp c2.cpp c3.cpp c4.cpp -o c4 -lm -lmysqlclient
c3.cpp is the file that needs mysql.h. This works perfectly on my local machine, but refuses to run on the server with the error
cannot find -lmysqlclient
I tried finding the libmysqlclient.so files on the server using the find command, I don't think they are present there
uname -a
reveals
SunOS opteron 5.10 Generic_139556-08 i86pc i386 i86pc
user#opteron 12:26:02 ~/c++/projname/
I realize that i need to link some libraries, but where and how?
Any help would be appreciated.
Thanks.
Whatever library packages u think is not installed can be installed using sudo apt-get install. But the problem is to find the right name of the package apt-get can understand. So how to do that ?! simple
use command : sudo apt-cache search <filename>
For eg.: in this case lmysqlclient
sudo apt-cache search mysqlclient
(remember to exclude 'l' from the actual name ,ie, mysqlclient and not lmysqlclient).
This outputs:
libmysqlclient-dev - MySQL database development files
In the above -libmysqlclient-dev is the name that apt-get can recognize and solve our cannot find lmysqlclient problem
so now type: sudo apt-get install libmysqlclient-dev from interface.
After its done, try making your required file.
Simplifying #SriHariY.S's answer-
Try installing it with sudo apt-get install libmysqlclient-dev.
Do you have the MySQL client libraries? Can you look for it as
find / -name "libmysqlclient.so" -type f -print 2>/dev/null
Also, you can use the -R flag on linker to hardlink the libmysqlclient as
g++ -R/usr/local/mysql/lib ....
Or, you can export the LD_LIBRARY_PATH_32 or LD_LIBRARY_PATH_64 as
export LD_LIBRARY_PATH_32=$MYSQL_HOME/lib
Urko,
On Ubuntu 18 I used this command to find a name of required package for fixing this error:
apt search lmysqlclient
After this I installed missing package:
sudo apt install libmariadbclient-dev-compat

Is there no mysql connector for python 2.7 on windows

While I see a bunch of links/binaries for mysql connector for python 2.6, I don't see one for 2.7
To use django, should I just revert to 2.6 or is there a way out ?
I'm using windows 7 64bit
django - 1.1
Mysql 5.1.50
Any pointers would be great.
For Python 2.7 on specific programs:
sudo chown -R $USER /Library/Python/2.7
brew install mysql#5.7
brew install mysql-connector-c
brew link --overwrite mysql#5.7
echo 'export PATH="/usr/local/opt/mysql#5.7/bin:$PATH"' >> ~/.bash_profile
sed -i -e 's/libs="$libs -l "/libs="$libs -lmysqlclient -lssl -lcrypto"/g' /usr/local/bin/mysql_config
pip install MySql-python
This solved all issues I was having running a program that ran on Python 2.7 on and older version of MySql
Try this one. This guy has done a good job and figured out the localization problem and gives a good link to windows binaries for what are you looking for. I hope it helps someday) Good luck!
this installer worked for me :
http://www.codegood.com/archives/129