VMware ESXi and vSphere Cluster Management
apt-cache Command: Search and Inspect APT Package Metadata
Learn how to use apt-cache to search packages, inspect metadata and dependencies, find reverse dependencies, list package names, and review APT cache statistics.
What apt-cache does
APT means Advanced Package Tool, the package-management system used by Debian, Ubuntu, and many related Linux distributions. apt-cache is a command-line query tool within the APT toolset.
apt-cache reads package metadata stored in the local package cache. This metadata describes packages available from configured repositories, including names, descriptions, versions, dependencies, conflicts, and package relationships.
apt-cache is primarily an information tool. It does not install, remove, or upgrade software. Use commands such as apt install, apt remove, and apt upgrade for package-changing operations. Use apt-cache when you need to investigate package information before performing one of those operations.
How package metadata reaches apt-cache
A repository is a software source that publishes packages and package indexes. APT repository definitions are commonly configured in /etc/apt/sources.list and in files under /etc/apt/sources.list.d/.
Run apt update to download current repository indexes and refresh the local metadata:
sudo apt updateAfter this command completes, apt-cache can query the refreshed local indexes. If the indexes are stale, incomplete, or missing, searches may return outdated results, no results, or fewer versions than expected. Repository errors during apt update can also prevent particular sources from contributing metadata.
Searching for packages
Use apt-cache search when you know what a package should do but do not know its exact name. Searches match package names and package descriptions.
apt-cache search network mapperThe output usually contains a package name followed by a short description. Review the results and select a likely candidate for further inspection:
apt-cache search network mapper
apt-cache show nmapBroad terms can produce a large result set. Narrow the search with more specific words, or filter the text output with a standard command such as grep:
apt-cache search network mapper | grep -i scannerSearch terms do not guarantee that every matching package is appropriate for your task. Treat search as discovery, then inspect the candidate's metadata, version, architecture, and relationships.
Viewing package information
Using apt-cache show
apt-cache show PACKAGE_NAME displays package control metadata in a relatively readable form. Depending on the package and enabled repositories, fields can include the package name, version, architecture, maintainer, description, dependencies, and related package information.
apt-cache show nmapMore than one record may appear when multiple versions are available from configured repositories. Read the version and repository-related fields carefully instead of assuming that the first visible record is the only available version.
Using apt-cache showpkg
apt-cache showpkg PACKAGE_NAME is more focused on package records and relationship data. It can show available versions, reverse dependencies, and dependency-related information in a format that is useful for examining the package cache.
apt-cache showpkg nmapshow is generally easier to read when you want a package description and control fields. showpkg is useful when you specifically need cache-level version and relationship details.
Inspecting cache statistics
Run apt-cache stats to summarize the local package metadata cache:
apt-cache statsThe report can include aggregate counts for package names, package structures, dependency relationships, provides entries, and other cache data. These figures help you understand the size and composition of the metadata database.
Checking unmet dependencies
apt-cache unmet reports unmet dependency relationships represented in the package cache:
apt-cache unmetThis is diagnostic metadata. It can help reveal relationships that the cache considers unsatisfied, but it does not by itself repair a broken installation or explain every transaction failure. Interpret the output alongside the exact error from the failing APT or dpkg operation.
If the result seems unexpected, refresh the indexes with sudo apt update. Also consider held packages, repository consistency, partially configured packages, and the specific operation that failed.
Displaying dependencies
Use apt-cache depends to inspect relationships declared by a package:
apt-cache depends nmapThe output may contain required, optional, and negative relationships. A dependency can also name alternatives or a virtual package. A virtual package is a capability name that one or more real packages can provide.
When output shows alternatives, do not assume every alternative must be installed. A relationship such as “package A or package B” means a suitable provider may satisfy the requirement.
Finding reverse dependencies
A reverse dependency is a package that references the named package through a relationship such as Depends, Recommends, Conflicts, or another package relationship. Use:
apt-cache rdepends nmapThis is especially useful before removing or replacing a shared library, service, runtime, or other foundational package. It helps identify packages that may be affected by the change.
Do not treat every result as proof of a hard installation requirement. Read the relationship type and inspect the relevant package metadata. Some results can represent recommendations, suggestions, conflicts, or other references rather than mandatory dependencies.
Listing known package names
apt-cache pkgnames lists package names known to the local APT cache:
apt-cache pkgnamesThe optional prefix limits results to names beginning with that string:
apt-cache pkgnames docThis can help discover exact package names when you know the beginning of a name. The results come from cached repository metadata, so they are not limited to software installed on the system.
apt-cache subcommands at a glance
Choosing between apt-cache and apt
apt-cache remains useful and is commonly available on APT-based systems. Modern user-facing APT commands also provide equivalents for common queries, especially apt search and apt show:
apt search network mapper
apt show nmapUse apt search or apt show for convenient interactive queries. Use apt-cache when inspecting the package cache, following existing documentation, using a familiar subcommand such as stats or unmet, or maintaining compatibility with scripts and procedures that already use apt-cache.
Neither tool replaces apt update. Query commands depend on the local indexes, so refresh those indexes when repository data may be outdated.
Practical investigation workflow
Refresh metadata:
sudo apt update.Search for a candidate:
apt-cache search network mapper.Read the candidate's descriptive metadata:
apt-cache show nmap.Inspect package records and versions when needed:
apt-cache showpkg nmap.Review requirements and optional relationships:
apt-cache depends nmap.Before replacing or removing a foundational package, check references:
apt-cache rdepends PACKAGE_NAME.Use the package-management command only after identifying the package and understanding the likely relationships.
Troubleshooting apt-cache results
No expected package appears in search results
Run
sudo apt updateand inspect repository errors.Check whether the repository containing the package is configured in
/etc/apt/sources.listor/etc/apt/sources.list.d/.Try broader or alternate search terms. The package name may not match the software's familiar name.
apt-cache shows no information for a package name
The package may not be available from enabled repositories.
The local cache may be stale or incomplete.
The supplied name may not be an actual package name.
Refresh indexes, search related terms, and check that repository configuration matches the distribution release.
pkgnames looks like an installed-package list
pkgnames lists names known to the cache, including packages that are merely available from repository indexes. To query installed packages instead, use an installed-package tool such as:
dpkg-query -WDependency output is confusing
Identify the label for each entry before deciding whether it is mandatory.
Distinguish Depends and PreDepends from Recommends and Suggests.
Look for alternatives and virtual package names.
Use
apt-cache show PACKAGE_NAMEfor a more readable view of package metadata.
apt-cache unmet reports a problem that is not resolved
The command reports relationships represented in the cache; it does not diagnose every transaction issue. Refresh the indexes, review the exact APT or dpkg error, and use appropriate package-repair or dependency-resolution procedures for the actual failure.
Key points
apt-cache queries locally cached APT package metadata.
sudo apt updaterefreshes the repository indexes that supply that metadata.Use
searchto discover packages,showfor readable metadata, andshowpkgfor package records and relationships.Use
dependsandrdependsto examine forward and reverse package relationships.Use
statsto understand cache composition, not to count installed software.Use
pkgnamesto list names known to the cache, optionally by prefix.Interpret optional relationships, alternatives, conflicts, and virtual packages carefully.