LinuxCommandLibrary

apt-cache

Search APT package information

TLDR

Search for a package in your current sources

$ apt-cache search [query]
copy

Show information about a package
$ apt-cache show [package]
copy

Show whether a package is installed and up to date
$ apt-cache policy [package]
copy

Show dependencies for a package
$ apt-cache depends [package]
copy

Show packages that depend on a particular package
$ apt-cache rdepends [package]
copy

SYNOPSIS

apt-cache [options] action [arguments]

PARAMETERS

-h, --help
    Show brief usage summary.

-v, --version
    Display program version.

-c, --config-file file
    Use specified configuration file.

-o, --option key=value
    Set low-level configuration option.

-p, --pkgcache file
    Use given file as package cache.

-q, --quiet
    Reduce output verbosity.

-i, --installed
    Limit output to installed packages.

--no-all-versions
    Ignore package version qualifiers.

--generate
    Generate dependency cache on demand.

DESCRIPTION

apt-cache is a versatile command-line utility on Debian-based systems like Ubuntu for querying and manipulating the local APT package cache. It enables users to search for packages, inspect details, analyze dependencies, and retrieve policy information without downloading or installing anything. The cache, built by apt update, stores metadata from repositories, making apt-cache ideal for offline exploration, scripting, and troubleshooting.

Common use cases include finding packages via keywords (apt-cache search), viewing extended info like versions and sources (apt-cache show), and dependency trees (apt-cache depends). It supports regex patterns and filters, enhancing precision. Unlike apt-get, it focuses purely on cache inspection, avoiding side effects.

Developers and admins use it to verify repository contents, check pinning policies, or generate reports. Output is human-readable or parseable for automation. Always run apt update first for accuracy, as the cache reflects last sync.

CAVEATS

Cache must be updated via apt update for current data; outdated cache yields stale info. Some actions are resource-intensive on large repositories. Largely superseded by unified apt command in APT 1.0+.

COMMON ACTIONS

search regex: Find packages by name/description.
show pkg: Detailed package record.
depends pkg: Recursive dependencies.
policy pkg: Pinning and candidate version.
pkgnames: List all package names.

CACHE LOCATION

Primary cache: /var/lib/apt/lists/ (lists), /var/cache/apt/pkgcache.bin (binary index).

HISTORY

Developed by Jason Gunthorpe as part of APT 0.3 in 1998 for Debian. Evolved through APT versions; key enhancements in APT 1.0 (2014) integrated features into apt, but apt-cache remains for advanced cache ops.

SEE ALSO

apt(8), apt-get(8), dpkg-query(1), aptitude(8)

Copied to clipboard