Product SiteDocumentation Site

6.3. The apt-cache Command

The apt-cache command can display much of the information stored in APT's internal database. This information is a sort of cache since it is gathered from the different sources listed in the sources.list file. This happens during the apt update operation.
The apt-cache command can do keyword-based package searches with apt-cache search keyword. It can also display the headers of the package's available versions with apt-cache show package. This command provides the package's description, its dependencies, the name of its maintainer, etc. Note that apt search, apt show, aptitude search, and aptitude show work in the same way.
Some features are more rarely used. For instance, apt-cache dumpavail displays the headers of all available versions of all packages. apt-cache pkgnames displays the list of all the packages which appear at least once in the cache.
One of the features which might come in handy more often is apt-cache policy, described in the following section.

6.3.1. The apt-cache policy Command

The apt-cache policy command displays the pinning priorities and distribution properties of each package source as explained in Section 6.2.5, “Managing Package Priorities”. It can also show the pinning priorities for all available versions and sources of a package. For the sources.list example used in Example 6.2, “/etc/apt/sources.list file for users of Debian Stable” and APT::Default-Release set to "/^bookworm(|-security|-updates)$/", the output will look like this:
$ apt-cache policy
Package files:
 100 /var/lib/dpkg/status
     release a=now
 990 http://deb.debian.org/debian bookworm-updates/non-free-firmware amd64 Packages
     release v=12-updates,o=Debian,a=stable-updates,n=bookworm-updates,l=Debian,c=non-free-firmware,b=amd64
     origin deb.debian.org
 990 http://deb.debian.org/debian bookworm-updates/main amd64 Packages
     release v=12-updates,o=Debian,a=stable-updates,n=bookworm-updates,l=Debian,c=main,b=amd64
     origin deb.debian.org
 990 http://security.debian.org/debian-security bookworm-security/non-free-firmware amd64 Packages
     release v=12,o=Debian,a=stable-security,n=bookworm-security,l=Debian-Security,c=non-free-firmware,b=amd64
     origin security.debian.org
 990 http://security.debian.org/debian-security bookworm-security/main amd64 Packages
     release v=12,o=Debian,a=stable-security,n=bookworm-security,l=Debian-Security,c=main,b=amd64
     origin security.debian.org
 990 http://deb.debian.org/debian bookworm/non-free-firmware amd64 Packages
     release v=12.5,o=Debian,a=stable,n=bookworm,l=Debian,c=non-free-firmware,b=amd64
     origin deb.debian.org
 990 http://deb.debian.org/debian bookworm/main amd64 Packages
     release v=12.5,o=Debian,a=stable,n=bookworm,l=Debian,c=main,b=amd64
     origin deb.debian.org
Pinned packages:
apt-cache policy can also show the pinning priorities for all available versions and sources of a given package.
$ apt-cache policy adb
adb:
  Installed: 1:29.0.6-28
  Candidate: 1:29.0.6-28
  Version table:
     1:33.0.3-2~bpo12+1 100
        100 http://deb.debian.org/debian bookworm-backports/main amd64 Packages
 *** 1:29.0.6-28 990
        990 http://deb.debian.org/debian bookworm/main amd64 Packages
        100 /var/lib/dpkg/status
Although there is a newer version of adb in the bookworm-backports repository, APT will not install it automatically based on the priority. One would have to use apt install adb/bookworm-backports or add a higher pinning priority to /etc/apt/preferences.d/adb.pref:
Package: adb
Pin: release o=Debian Backports,n=bookworm-backports
Pin-Priority: 1001
$ apt-cache policy limnoria
adb:
  Installed: 1:29.0.6-28
  Candidate: 1:33.0.3-2~bpo12+1
  Version table:
     1:33.0.3-2~bpo12+1 1001
        100 http://deb.debian.org/debian bookworm-backports/main amd64 Packages
 *** 1:29.0.6-28 990
        990 http://deb.debian.org/debian bookworm/main amd64 Packages
        100 /var/lib/dpkg/status