96

Is there a way to install jq JSON processor on Ubuntu 10.04?

I Tried the usual sudo apt-get install jq but got the error E: Couldn't find package jq

Ste-3PO
  • 1,165
  • 1
  • 9
  • 18

5 Answers5

172

It is possible to perform sudo apt-get install jq however you need to inform the system where to find jq.

ℹ️ Note: Ubuntu 14+ users can skip to step 3!

Install

  1. Open your sources file in a text editor:

     sudo vim /etc/apt/sources.list
    
  2. Add the following line to the end of that file (note deb is not a command, more info):

    deb http://us.archive.ubuntu.com/ubuntu vivid main universe

  3. Then re-index apt-get so that it can find jq:

     sudo apt-get update
    
  4. Then do the normal install and you should be the proud new user of jq!

     sudo apt-get install jq
    

Test

Test it works! Try this to see it pretty print some example json

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"
}
Stefan Collier
  • 4,314
  • 2
  • 23
  • 33
  • 2
    On Ubuntu 14, I had to use old release source "deb http://old-releases.ubuntu.com/ubuntu vivid main universe" – vaichidrewar Feb 20 '18 at 23:55
  • 3
    `sudo apt-get update` spit out some errors like "Some index files failed to download. They have been ignored, or old ones used instead." and `sudo apt-get install jq` still fails afterwards. How to go about fixing this (Ubuntu 17.04)? Automatic updates fail as well, telling me to check my network connection, but other internet access works fine (Git, Firefox, ...). It is running in a VM btw. – CodeManX Apr 25 '18 at 12:34
  • 1
    I was able to `apt-get install jq` just now on a Raspberry PI without altering `sources.list` – ᴍᴇʜᴏᴠ Aug 15 '18 at 06:21
  • 1
    Oh nice! Unfortunately Ubuntu 10.04 (and similar) users don't have it so easy though. – Stefan Collier Aug 15 '18 at 08:53
  • 3
    I was getting `E: Couldn't find package jq` until I did `sudo apt-get update`. So for versions 14+ it's better to start from step 3. – artifex Feb 09 '21 at 15:54
  • what about without sudo permissions? my cluster doesn't let me install it and IT is fine if I install things on my own. – Charlie Parker Feb 17 '23 at 20:42
43

Since Ubuntu 16.04LTS xenial you do not need to modify /etc/apt/sources.list, just run

sudo apt-get install jq

jq 1.5 is in the official Debian and Ubuntu repositories.

Nik
  • 2,885
  • 2
  • 25
  • 25
5

I think you're missing the repo: http://installion.co.uk/ubuntu/vivid/universe/j/jq/install/index.html

Somaiah Kumbera
  • 7,063
  • 4
  • 43
  • 44
4

Download & build from source as described in https://stedolan.github.io/jq/download/, last section called "From source on Linux, OS X, Cygwin, and other POSIX-like operating systems".

Hans Z.
  • 50,496
  • 12
  • 102
  • 115
  • 2
    I wasn't aware of existence of jq in a proper distribution channel as suggested in the other answers but since that is the case, one of the other answers should be the preferred/accepted one. – Hans Z. Nov 03 '17 at 12:44
0

If you don't have sudo permission do this:

#!/usr/bin/env bash

# conda activate jq_install_env

# - Install jq without sudo
# Clone the jq repository from GitHub
cd $HOME
git clone https://github.com/stedolan/jq.git $HOME/jq
cd $HOME/jq
git submodule update --init

# Compile jq from source
cd $HOME/jq
autoreconf -fi
./configure --with-oniguruma=builtin --disable-maintainer-mode --prefix=$HOME/.local
make -j8 && make check
make install
ls $HOME/.local
ls $HOME/.local/bin

# Add the directory where the jq binary file is located to your PATH environment variable
echo 'PATH=$PATH:~/.local/bin/' >> $HOME/.bashrc.lfs
export PATH=$PATH:~/.local/bin/
echo $PATH | tr ':' '\n'

# Reload your shell configuration file to update your PATH environment variable
source $HOME/.bashrc.lfs

# Verify that jq is installed and working
jq --version

reference: https://suzyahyah.github.io/misc/2020/03/31/jq-without-sudo.html

in case link dies:

Landing Page...
AboutCategoriesAdvisors
Recipe for building jq from source without admin(sudo) rights
Mar 31, 2020

This took me some time to install. Just putting it out there in case it helps someone.
Get the latest jq from github

git clone https://github.com/stedolan/jq.git

Update submodules (onigurama)

git submodule update --init

Copy missing auxiliary files

autoreconf -fi

Install into {YOUR_HOME_DIR} with onigurama (regex library)

./configure --with-oniguruma=builtin --disable-maintainer-mode --prefix={YOUR_HOME_DIR}.local

Check that we have all the dependencies downloaded and install

make -j8 && make check

make install

Finally, add this to your ~/.bashrc and to call jq from anywhere. Remember to >source ~/.bashrc and you should be good to go.

export PATH=$PATH:~/.local/bin/

« The Sigmoid in Regression, Neural Network Activation and LSTM GatesA minimum keystroke (py)Debugger for Lazy ML/DS people who don't IDE »
Quality means doing it right when no one is looking - Henry Ford
 suzyahyah
 suzyahyah
The best time to plant a tree was 20 years ago. The second best time is now. - Japanese proverb

Since October 2017
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323