apt-cache 命令可显示 APT 内部数据库里的多种信息。这些信息是从 sources.list 文件内聚集不同来源的缓存。于运行 apt update 运作时产生的。
apt-cache 命令可以通过 apt-cache search keyword做基于关键词的软件包搜索。也能使用 apt-cache show 软件包名称 显示可用版本软件包的标头。这个命令提供软件包说明、依赖性、维护者名称等。请注意,apt search、apt show、aptitude search 和 aptitude show 都以同样方式运作。
apt-cache dumpavail 显示所有软件包全部版本的标头。apt-cache pkgnames 显示出现在缓存至少一次的软件包清单。
apt-cache policy, described in the following section.
apt-cache policy command displays the pinning priorities and distribution properties of each package source as explained in 第 6.2.5 节 “软件包优先级管理”. It can also show the pinning priorities for all available versions and sources of a package. For the sources.list example used in 例 6.2 “给 Debian 稳定版用户的 /etc/apt/sources.list 文件” and APT::Default-Release set to "/^bookworm(|-security|-updates)$/", the output will look like this:
$apt-cache policyPackage 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 可以显示指定软件包所有可用版本的固定优先级和源。
$apt-cache policy adbadb: 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
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 limnoriaadb: 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