apt-cache

package managementlinux
The apt-cache command is one of the most frequently used commands in Linux/Unix-like operating systems. apt-cache The apt-cache command is used to query the APT package cache on Debian-based systems, providing information about available packages, dependencies, versions, and package details.

Quick Reference

Command Name:

apt-cache

Category:

package management

Platform:

linux

Basic Usage:

apt-cache [options] [arguments]

Common Use Cases

  • 1

    Package information lookup

    Search for package details, dependencies, and metadata

  • 2

    Dependency resolution

    Check package dependencies and reverse dependencies

  • 3

    Package discovery

    Find available packages and their descriptions

  • 4

    Repository analysis

    Analyze package repository contents and statistics

Syntax

apt-cache [options] command

Options

Option Description
-h, --help Display help message and exit
-p, --pkg-cache Select the file to use as the package cache
-s, --src-cache Select the file to use as the source cache
-q, --quiet Quiet mode; produce output suitable for logging
-i, --important Print only important dependencies (used with depends)
-f, --full Print full package records when searching
-a, --all-versions Print full records for all available versions
-g, --generate Automatically regenerate the package cache if needed
--names-only Only search on package names, not descriptions
--all-names Make pkgnames return all names, including virtual packages
--recurse Make depends/rdepends recursively list all dependencies
--installed Only consider installed packages (with policy/show)
-v, --version Display version information and exit

Examples

How to Use These Examples

The examples below show common ways to use the apt-cache command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

Basic Examples:

Search for a package by name
apt-cache search firefox
Display package details
apt-cache show nginx
Check package dependencies
apt-cache depends python3
Show package statistics
apt-cache stats
List available package versions
apt-cache policy mysql-server

Advanced Examples:

Search with regular expressions
apt-cache search --names-only '^python3-'
Find reverse dependencies (what depends on a package)
apt-cache rdepends libc6
Show all package versions and their download size
apt-cache show --all-versions imagemagick
Display package in machine-readable format
apt-cache showpkg git
Check what packages provide a specific file
apt-cache pkgnames libssl | grep dev
Dump complete package records
apt-cache dump
Find what packages are related to a given package
apt-cache dotty bash | dot -Tpng > bash_deps.png
Show raw package records
apt-cache dumpavail | grep ^Package | head -10

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

Common Commands:

The apt-cache tool provides several commands for querying the APT package database:

  • search: Search for packages by name and description
  • show: Display detailed information about specific packages
  • showpkg: Display information about a package in a machine-readable format
  • depends: Show dependencies of a package
  • rdepends: Show reverse dependencies (packages that depend on the specified package)
  • policy: Show installation candidate version and priority information
  • madison: Display available versions in a tabular format (similar to apt-cache policy)
  • pkgnames: List all package names in the system
  • stats: Display overall statistics about the cache
  • unmet: Show unmet dependencies in the cache
  • dump: Show all package records in the cache
  • dotty: Generate package dependency graphs in DOT format

Package Cache:

The apt-cache command works with the APT package cache, which:

  • Contains information about available packages from repositories configured in /etc/apt/sources.list
  • Is updated when you run apt update or apt-get update
  • Is stored in /var/lib/apt/lists/
  • Can be used without internet connectivity once updated
  • Includes package metadata like dependencies, versions, descriptions, and sizes

Searching Tips:

  • Use apt-cache search --names-only to search only in package names for faster, more focused results
  • Search terms are automatically joined with logical AND; use regular expressions for more complex searches
  • Combine with grep for additional filtering: apt-cache search editor | grep 'text'
  • For case-sensitive searches: apt-cache search --names-only python | grep -i 'Django'
  • Search for multiple related packages: apt-cache search --names-only 'php[0-9]+-'

Understanding Dependencies:

When using apt-cache depends or apt-cache rdepends, you'll see different dependency types:

  • Depends: Required for the package to function properly
  • Recommends: Highly recommended but not strictly required
  • Suggests: Optional packages that enhance functionality
  • Conflicts: Packages that cannot be installed simultaneously
  • Replaces: Packages that this package replaces
  • Provides: Virtual packages that this package provides

Integration with Other Tools:

  • Use apt-cache dotty with Graphviz to visualize package dependencies: apt-cache dotty package | dot -Tpng > package_deps.png
  • Combine with apt or apt-get for package management workflows: apt-cache search package && sudo apt install package
  • Use in scripts to check package availability before installation
  • Parse output with tools like awk or grep for specific information

Performance Considerations:

  • The apt-cache command is generally fast as it reads from local files and doesn't require internet access
  • For very large package lists, some operations like apt-cache dump may be slow
  • The --recurse option with depends/rdepends can be resource-intensive for packages with many dependencies
  • Use apt-cache policy instead of apt-cache show when you only need version information

Important Notes:

  • Unlike apt commands, apt-cache typically doesn't require root privileges
  • If the cache is out of date, run sudo apt update to refresh it
  • The apt-cache command is more scriptable than apt search, with more predictable output format
  • For most interactive use cases, the newer apt command provides similar functionality with a more user-friendly interface
  • The output format of apt-cache commands may change between APT versions

Common Use Cases

Package information lookup

Search for package details, dependencies, and metadata

Dependency resolution

Check package dependencies and reverse dependencies

Package discovery

Find available packages and their descriptions

Repository analysis

Analyze package repository contents and statistics

Package planning

Research packages before installation to understand their impact

Related Commands

These commands are frequently used alongside apt-cache or serve similar purposes:

Use Cases

1

Package information lookup

Search for package details, dependencies, and metadata

2

Dependency resolution

Check package dependencies and reverse dependencies

3

Package discovery

Find available packages and their descriptions

4

Repository analysis

Analyze package repository contents and statistics

5

Package planning

Research packages before installation to understand their impact

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the apt-cache command works in different scenarios.

$ apt-cache
View All Commands
apt-cache - Linux Command Guide