apt-cache: Usage, Options & Common CI Errors
apt-cache inspects the package index - search, show details, and check available versions.
apt-cache is the read-only counterpart to apt-get: it answers "does this package exist, what version, and from which repo?" In CI it is invaluable for debugging why an install picks the wrong version.
What it does
apt-cache queries the local APT index (populated by apt-get update). It does not touch the network or install anything. apt-cache policy shows which version would be installed and the priority of each source; apt-cache madison lists all available versions of a package.
Common usage
apt-cache search nginx
apt-cache show nginx
apt-cache policy nginx # candidate version + sources
apt-cache madison docker-ce # all versions, for pinning
apt-cache depends curlCommon errors in CI
Empty output from apt-cache search or "Unable to locate package" downstream usually means apt-get update has not run, so the index is empty. apt-cache policy showing "Candidate: (none)" means no source provides an installable version for your release - you likely need to add a repo or PPA. When an install grabs an unexpected version, apt-cache policy reveals the pin priorities causing it. Note apt (not apt-get) prints a "this CLI is unstable for scripts" warning; use apt-cache/apt-get in scripts.
Options
| Subcommand | What it does |
|---|---|
| search <term> | Search package names and descriptions |
| show <pkg> | Show package metadata |
| policy <pkg> | Show candidate version and source priorities |
| madison <pkg> | List every available version (for pinning) |
| depends / rdepends | Show dependencies / reverse dependencies |