apt-cache Command in Linux: Search, Policy & Dependencies (Ubuntu/Debian)

Deepak Prasad
Tested on Ubuntu 25.04 (Plucky Puffin)
Package apt 3.0.0
Applies to Ubuntu, Debian, Kali Linux, Linux Mint, Pop!_OS, Raspberry Pi OS, elementary OS, Zorin OS, Parrot OS, MX Linux
Privilege read-only (no elevated privileges)
Man page apt-cache(8)
Scope Read-only APT index queries: search, metadata, policy, and forward or reverse dependencies without network access after apt update.
Related guides apt command
dpkg command
Linux commands cheat sheet

apt-cache — quick reference

Search and list

Find package names in the local index — no root required.

When to use Command
Search names and descriptions for a keyword apt-cache search pattern
Search package names only apt-cache search --names-only pattern
List package names matching a prefix apt-cache pkgnames prefix

Package records

When to use Command
Show readable metadata (version, depends, size) apt-cache show package_name
Show versions, reverse depends, and file mapping apt-cache showpkg package_name
Show installed vs candidate version and pin priority apt-cache policy package_name
List available versions from all sources apt-cache madison package_name

Dependencies

When to use Command
Show packages this package depends on apt-cache depends package_name
Show packages that depend on this package apt-cache rdepends package_name
Walk the dependency tree recursively apt-cache depends --recurse package_name
Limit depends output to important packages apt-cache depends --important package_name

Diagnostics

When to use Command
List packages with unmet dependencies in the cache apt-cache unmet

Help and version

When to use Command
Show built-in usage summary apt-cache --help
Print apt version (apt-cache ships with apt) apt-cache --version

apt-cache — command syntax

apt-cache queries data under /var/lib/apt/lists/ populated by apt update. Synopsis from apt-cache --help on Ubuntu 25.04 (apt 3.0.0):

text
apt-cache [options] command
       apt-cache [options] show pkg1 [pkg2 ...]

Most used commands:
  showsrc - Show source records
  search - Search the package list for a regex pattern
  depends - Show raw dependency information for a package
  rdepends - Show reverse dependency information for a package
  show - Show a readable record for the package
  pkgnames - List the names of all packages in the system
  policy - Show policy settings

apt-cache does not install or remove packages. Refresh the index with sudo apt update when you need the newest repository data.


apt-cache — command examples

Essential Search the local package index

Find the exact package name before install — works offline against the last apt update.

Run the command:

bash
apt-cache search --names-only '^curl$'

Sample output:

The example below transfers data with curl over HTTP(S); the curl command is a quick reference for flags and syntax.

output
curl - command line tool for transferring data with URL syntax

Omit --names-only to match descriptions too (more results, slower to scan).

Essential See installed vs candidate version

policy explains which version apt prefers and why — essential when upgrades stall or multiple repos supply the same name.

Run the command:

bash
apt-cache policy curl

Sample output:

output
curl:
  Installed: 8.12.1-3ubuntu1
  Candidate: 8.12.1-3ubuntu1
  Version table:
 *** 8.12.1-3ubuntu1 1001
       1001 http://archive.ubuntu.com/ubuntu plucky/main amd64 Packages
        100 /var/lib/dpkg/status

The *** marks the version apt would install. Priority 1001 beats plain 500 from a standard mirror.

Essential Read full package metadata with show

show prints the same fields administrators skim before approving an install.

Run the command:

bash
apt-cache show curl | head -12

Sample output:

output
Package: curl
Architecture: amd64
Version: 8.12.1-3ubuntu1
Multi-Arch: foreign
Priority: optional
Section: web
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Curl Maintainers <team+curl@tracker.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 491
Depends: libc6 (>= 2.38), libcurl4t64 (= 8.12.1-3ubuntu1), zlib1g (>= 1:1.1.4)

Compare with apt show curl — similar fields, different formatter.

Common List forward dependencies

Know what libraries a package pulls before installing on a minimal system.

Run the command:

bash
apt-cache depends curl | head -6

Sample output:

output
curl
  Depends: libc6
  Depends: libcurl4t64
  Depends: zlib1g

Add --recurse for the full tree (can be long on desktop metapackages).

Common Find reverse dependencies before removal

See which installed packages would break if you remove a library.

Run the command:

bash
apt-cache rdepends curl | head -8

Sample output:

output
curl
Reverse Depends:
  debian-goodies
  zfs-test
  mariadb-plugin-connect
  libsoup2.4-tests
  libsoup-3.0-tests
  djvulibre-bin

Not every listed package is installed — cross-check with dpkg -l or apt list --installed.

Common List names matching a prefix

Quick autocomplete-style listing when you know the first letters of a package family.

Run the command:

bash
apt-cache pkgnames curl | head -5

Sample output:

output
curl
curlftpfs

Useful in scripts that enumerate related packages.

Advanced Debug versions with showpkg

showpkg exposes cache file paths, MD5 sums, and reverse-depends — handy when mirroring or debugging stale indexes.

Run the command:

bash
apt-cache showpkg curl | head -14

Sample output:

output
Package: curl
Versions: 
8.12.1-3ubuntu1 (/var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_plucky_main_binary-amd64_Packages) (/var/lib/dpkg/status)
 Description Language: 
                 File: /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_plucky_main_binary-amd64_Packages
                  MD5: f83293d10df083ae6f7bb7d01642913c
 Description Language: en
                 File: /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_plucky_main_i18n_Translation-en
                  MD5: f83293d10df083ae6f7bb7d01642913c

Reverse Depends:

When MD5s disagree across list files, run sudo apt update.

Advanced Compare repo versions with madison

madison lists every indexed version and the repository that provides it — similar to apt list -a.

Run the command:

bash
apt-cache madison curl

Sample output:

output
curl | 8.12.1-3ubuntu1 | http://archive.ubuntu.com/ubuntu plucky/main amd64 Packages

Multiple rows appear when PPAs or security pockets ship alternate versions.


apt-cache — when to use / when not

Use apt-cache when Use something else when
You need read-only metadata from the local APT cache You are installing or removingapt
You are offline but the index was updated recently You need fresh mirror data — sudo apt update first
You debug pinning, policy, or dependencies You want friendly search output — apt search / apt show
You script exact cache queries in maintenance tools You query installed files onlydpkg -L / dpkg -S

apt-cache apt search / apt show
Privilege User (read-only) User for search/show
Output style Dense, script-oriented Colored, paginated lists
Policy / madison / showpkg Native subcommands Not available
Typical use Diagnostics and automation Interactive admin

Many admins use apt for daily search and apt-cache for policy, madison, and rdepends.


apt-cache — interview corner

What does apt-cache do?

apt-cache queries the local APT package index built by apt update. It searches names, prints metadata, shows policy priorities, and lists dependencies — without installing anything and without network once lists are cached.

A strong answer is:

"apt-cache is read-only metadata from /var/lib/apt/lists — search, show, policy, depends, and rdepends offline after an update."

Do you need sudo for apt-cache?

No. apt-cache never modifies the system. Any user who can read /var/lib/apt/lists/ can run apt-cache search, policy, and depends.

Installing packages still requires sudo through apt or apt-get.

A strong answer is:

"apt-cache is read-only — no sudo. I use it as a regular user to inspect packages before escalating for install."

What does apt-cache policy show?

For each package name, policy prints:

  • Installed version on disk
  • Candidate version apt would install next
  • Version table — each available version, its pin priority, and source URI

High-priority pins (for example 1001 from security pockets) beat lower-priority mirrors.

A strong answer is:

"policy shows installed vs candidate and the pin priority table — I use it when apt won't upgrade or multiple repos conflict."

What is the difference between depends and rdepends?
Command Direction
apt-cache depends pkg What pkg needs (forward dependencies)
apt-cache rdepends pkg What needs pkg (reverse dependencies)

Run rdepends before removing shared libraries to see potential breakage.

A strong answer is:

"depends is what the package requires; rdepends is who requires the package — critical before removals."

Why can apt-cache show outdated information?

apt-cache only reads cached list files. If nobody ran apt update recently, Candidate versions may lag behind the mirror.

Fix: sudo apt update, then re-run apt-cache policy.

A strong answer is:

"It reads the local index only — stale until apt update. I refresh lists before trusting candidate versions."


Troubleshooting

Symptom Likely cause Fix
Empty search results Stale or minimal index sudo apt update
Package has no installation candidate Not in enabled repos Check apt-cache policy; edit sources
policy shows only installed line Package not in any list file Enable component (universe, etc.) and update
rdepends lists hundreds of names Metapackage or popular library Filter with grep; verify with dpkg -l
showsrc errors about deb-src No source repositories enabled Add deb-src URIs to sources; use apt-cache show for binary metadata
Differs from apt show Formatter only Compare Version and Depends fields

Rohan Timalsina

is a technical writer and Linux enthusiast who writes practical guides on Linux commands and system administration. He focuses on simplifying complex topics through clear explanations.

  • Linux
  • HTML5
  • JavaScript
  • Web Design
  • Front-end Web Development