How to Install jq on Ubuntu

Install jq on Ubuntu with sudo apt install jq, verify with jq --version, pretty-print and filter JSON from files and curl output, fix Unable to locate package jq with apt update, and optionally install jq 1.8.x from jqlang GitHub releases.

Published

Updated

Read time 5 min read

Reviewed byDeepak Prasad

Install jq on Ubuntu banner with apt install jq and pretty-printed JSON output

jq is the standard command-line JSON processor for Linux—think grep/awk, but for structured data. You pipe API responses, log lines, and config files through jq filters to pretty-print, extract fields, filter arrays, and reshape output for scripts. On Ubuntu, jq lives in the main repository as a normal apt package (available since Ubuntu 16.04+ per Stack Overflow); you do not need to edit sources.list on current LTS releases.

This guide shows how to install jq on Ubuntu, verify the binary, run practical examples with files and cURL, fix Unable to locate package jq, and optionally install a newer build from jqlang/jq releases. I ran the commands on Ubuntu 25.04 and kept real output below.

Tested on: Ubuntu 25.04 (Plucky Puffin); kernel 6.14.0-37-generic; jq 1.7.1 (jq --version prints jq-1.7).

NOTE
On a fresh Ubuntu install, run sudo apt update before apt install jq. Stack Overflow and Lindevs both treat that as step one—without it apt may suggest Snap or report the package missing even though jq exists in the archive.

Quick command summary

Task Command
Refresh indexes sudo apt update
Install (recommended) sudo apt install -y jq
Check candidate apt-cache policy jq
Verify jq --version and which jq
Pretty-print jq . file.json or echo '{"a":1}' | jq .
Extract a field jq '.data[0].name' file.json
With curl curl -fsS URL | jq .
Remove sudo apt purge -y jq

Choose an install path

Method Best for Jump to
apt (jq) Everyday use, security updates, scripts Install from apt
Local .deb Offline install or pinning an exact Ubuntu build Install a downloaded .deb
GitHub release binary Newer upstream jq (1.8.x) without compiling Upstream binary
Build from source Custom builds, no root (user prefix) Build from source

For most readers, sudo apt install jq is enough.


Prerequisites

  • Ubuntu 22.04 LTS, 24.04 LTS, or newer (25.04 tested here) on amd64 or arm64.
  • sudo for apt installs.
  • Working apt repositories (main at minimum).
  • For API examples: cURL and outbound HTTPS.

What you are installing

Package Role
jq CLI binary at /usr/bin/jq
libjq1 Shared library the jq command links against
libonig5 Oniguruma regex engine used by jq filters

sudo apt install jq pulls dependencies automatically—you do not install libjq1 separately for normal CLI use.


Refresh package lists and inspect the candidate:

bash
sudo apt update
apt-cache policy jq

On Ubuntu 25.04:

text
jq:
  Installed: (none)
  Candidate: 1.7.1-3ubuntu1.1
  Version table:
     1.7.1-3ubuntu1.1 500
        500 http://archive.ubuntu.com/ubuntu plucky-updates/main amd64 Packages

Install:

bash
sudo apt install -y jq

Verify:

bash
jq --version
which jq
command -v jq
text
jq-1.7
/usr/bin/jq
/usr/bin/jq

The Debian version is 1.7.1; jq --version abbreviates it as jq-1.7. You also get man jq under /usr/share/man/man1/jq.1.gz.


First use: pretty-print and filter JSON

Pretty-print inline JSON

The . filter is the identity operator—it reformats JSON without changing values (jqlang.org):

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

Read from a file and extract fields

bash
echo '{"status":"success","data":[{"name":"John","age":25},{"name":"James","age":29}]}' > /tmp/example.json
jq '.' /tmp/example.json
jq '.data[1].name' /tmp/example.json

Second command output:

text
"James"

Combine with curl

bash
curl -fsS https://httpbin.org/get | jq '.headers.Host'
text
"httpbin.org"

Use jq '.headers' to dump the whole headers object, or jq -c for compact single-line output in scripts.


Optional: install a local .deb

When you need an exact Ubuntu package file (air-gapped host or version pin), download the .deb for your release from packages.ubuntu.com and install locally:

bash
sudo apt install ./jq_1.7.1-3ubuntu1.1_amd64.deb

apt install ./file.deb resolves dependencies from your configured repositories—prefer this over raw dpkg -i when the network is available.


Optional: install jq from GitHub releases

Ubuntu apt may lag the latest jq release ( 1.8.2 at the time of writing). For a standalone binary without compiling:

bash
mkdir -p ~/.local/bin
curl -fsSL -o ~/.local/bin/jq \
  https://github.com/jqlang/jq/releases/download/jq-1.8.2/jq-linux-amd64
chmod +x ~/.local/bin/jq
export PATH="$HOME/.local/bin:$PATH"
jq --version
text
jq-1.8.2

On arm64, use jq-linux-arm64 instead of jq-linux-amd64. Add export PATH="$HOME/.local/bin:$PATH" to ~/.bashrc if you want the binary in every shell.

WARNING
A user-installed ~/.local/bin/jq can shadow /usr/bin/jq when your PATH lists ~/.local/bin first. Know which binary you are running: type -a jq.

Optional: build jq from source

Follow the jqlang/jq README when you need a custom build or cannot use apt. On Ubuntu, install build dependencies first:

bash
sudo apt install -y autoconf automake libtool make gcc git
git clone https://github.com/jqlang/jq.git
cd jq
git submodule update --init
autoreconf -i
./configure --with-oniguruma=builtin --prefix="$HOME/.local"
make -j"$(nproc)"
make check
make install

Use --prefix="$HOME/.local" when you lack sudo—same pattern as no-root jq builds discussed on Stack Overflow.


Uninstall jq

Apt install:

bash
sudo apt purge -y jq
sudo apt autoremove -y

See remove unused packages on Ubuntu if apt reports orphaned libraries after purge.

Manual GitHub binary:

bash
rm -f ~/.local/bin/jq

Troubleshooting

Symptom Likely cause Fix
Unable to locate package jq Stale apt indexes sudo apt update, then retry install
apt suggests snap install jq Indexes empty or minimal image Run apt update; prefer apt jq over Snap for /usr/bin/jq
jq: command not found Not installed or PATH sudo apt install jq or add ~/.local/bin to PATH
parse error: Invalid numeric literal Input is not JSON Validate with jq . on a file; check for HTML error pages from curl
Cannot index array with string Wrong filter for JSON shape Inspect structure first: jq 'type' or jq 'keys'
Two different jq --version values Multiple installs on PATH type -a jq; remove duplicate or adjust PATH order
Need jq 1.8+ features Ubuntu ships 1.7.x Use GitHub release binary

References


Summary

Installing jq on Ubuntu is usually two commands: sudo apt update and sudo apt install -y jq. Verify with jq --version, pretty-print with jq ., and drill into APIs using curl … | jq 'filter'. If apt cannot see the package yet, update indexes before chasing Snap or third-party repos. Reach for a jqlang/jq release binary only when you need features in a newer upstream version than your Ubuntu archive ships.


Frequently Asked Questions

1. How do I install jq on Ubuntu?

Run sudo apt update && sudo apt install -y jq. The jq package pulls in libjq1 and libonig5 automatically. Verify with jq --version and which jq (typically /usr/bin/jq).

2. Why does apt say Unable to locate package jq?

Fresh images sometimes have stale package indexes. Run sudo apt update first—Stack Overflow reports this on new Ubuntu 24.04 installs before jq appears. Also confirm main/universe repositories are enabled in /etc/apt/sources.list.d/.

3. Is jq installed by default on Ubuntu?

No. Minimal server and container images usually omit jq. Run command -v jq; if empty, install from apt. Cloud-init and CI images may add it in custom AMIs, but do not assume it is present.

4. What is the difference between jq, libjq1, and libonig5?

jq is the CLI at /usr/bin/jq. libjq1 is the shared library behind the binary. libonig5 is the Oniguruma regex library jq uses for pattern matching in filters—apt installs it as a dependency.

5. How do I pretty-print JSON on Ubuntu?

Pipe JSON to jq with the identity filter: echo '{"a":1}' | jq . or jq . file.json. The dot filter formats output while leaving data unchanged.

6. How do I install a newer jq than Ubuntu apt provides?

Download the jq-linux-amd64 (or arm64) binary from jqlang/jq GitHub releases, chmod +x, and place it in ~/.local/bin or /usr/local/bin. Ubuntu 25.04 ships jq 1.7.x; upstream 1.8.2 was available from GitHub at the time of writing.

7. Should I use apt or Snap for jq on Ubuntu?

Prefer sudo apt install jq. The community Snap exists but apt integrates with man pages, security updates, and scripts that expect /usr/bin/jq on PATH.

8. How do I uninstall jq from Ubuntu?

Run sudo apt purge -y jq. libjq1 and libonig5 may be removed if nothing else depends on them. Remove a manually downloaded binary from ~/.local/bin or /usr/local/bin separately.

9. How do I use jq with curl on Ubuntu?

Install curl if needed, then pipe API output to jq: curl -fsS https://api.example.com/data | jq .items[0].name. Install jq first—curl alone does not parse JSON.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …