Debian 管理员手册 6.3. apt-cache 命令

ga站群域名注册6.3. apt-cache 命令

apt-cache 命令可显示 APT 内部数据库里的多种信息。这些信息是从 sources.list 文件内聚集不同来源的缓存。于运行 apt update 运作时产生的。

术语 缓存

缓存是一种暂存系统,近用方法昂贵 (讲究性能) 时,用于加快常用数据的取用速度。这个概念应用范围极广,从微处理器核心至高端保存系统。

在 APT 的环境,参照 软件包名称 文件是他们在 Debian 镜射站的位置。也就是说,近用数据库软件包时,每次都通过网络读取,极无劾率。所以,APT 在其文件内保存一个复本 (在 /var/lib/apt/lists/) 每次搜索本地的文件即可。同样的,/var/cache/apt/archives/ 保存已经下载的软件包避免在移除后又需要时的重复下载行为。

On the other hand, it is mandatory to run apt update regularly to update the cache. Otherwise your package search results will always miss the latest updates distributed by the Debian mirrors.

apt-cache 命令可以做键词软件包搜索 apt-cache search 键词。也能显示软件包标头的可用版本 apt-cache show 软件包名称。这个命令提供软件包说明、其相依性、维护者名称等。apt search、apt show、aptitude search、aptitude show 都以同样方式运作。

其他 axi-cache

apt-cache search 是基础的工具,应用在 grep 软件包描述。输入过多键词可能送回大量结果或完全无数据。

axi-cache search term, on the other hand, provides better results, sorted by relevancy. It uses the Xapian search engine and is part of the apt-xapian-index package which indexes all package information (and more, like the .desktop files from all Debian packages). It knows about tags (see sidebar 更进一步标签字段) and returns results in a matter of milliseconds.

$ axi-cache search package use::searching

100 results found.

Results 1-20:

100% packagesearch - GUI for searching packages and viewing package information

99% apt-utils - package management related utility programs

98% whohas - query multiple distributions' package archives

98% dpkg-awk - Gawk script to parse /var/lib/dpkg/{status,available} and Packages

97% apt-file - search for files within Debian packages (command-line interface)


90% wajig - unified package management front-end for Debian

More terms: debtags debian paket dpkg search pakete tools

More tags: role::program interface::commandline works-with::software:package suite::debian admin::package-management scope::utility network::client

`axi-cache more' will give more results

有些功能极少用到。例如,apt-cache policy 显示软件包来源及个别软件包的优先性。另个例子是apt-cache dumpavail 显示所有软件包全部版本的标头。apt-cache pkgnames 显示出现在缓存至少一次的软件包清单。

秘诀 apt-cache policy

The 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 “/etc/apt/sources.list 给 Debian Stable 使用者的文件” and APT::Default-Release set to "buster", the output will look like this:

$ apt-cache policy

Package files:

100 /var/lib/dpkg/status

release a=now

100 buster-backports/contrib amd64 Packages

release o=Debian Backports,a=buster-backports,n=buster-backports,l=Debian Backports,c=contrib,b=amd64


100 buster-backports/main amd64 Packages

release o=Debian Backports,a=buster-backports,n=buster-backports,l=Debian Backports,c=main,b=amd64


990 buster/non-free amd64 Packages

release v=10.0,o=Debian,a=stable,n=buster,l=Debian,c=non-free,b=amd64


990 buster/contrib amd64 Packages

release v=10.0,o=Debian,a=stable,n=buster,l=Debian,c=contrib,b=amd64


990 buster/main amd64 Packages

release v=10.0,o=Debian,a=stable,n=buster,l=Debian,c=main,b=amd64


990 buster/updates/main amd64 Packages

release v=10,o=Debian,a=stable,n=buster,l=Debian-Security,c=main,b=amd64


apt-cache policy can also show the pinning priorities for all available versions and sources of a given package.

$ apt-cache policy iptables


Installed: 1.8.2-4

Candidate: 1.8.2-4

Version table:

1.8.3-2~bpo10+1 100

100 buster-backports/main amd64 Packages

*** 1.8.2-4 990

990 buster/main amd64 Packages

100 /var/lib/dpkg/status

Although there is a newer version of iptables in the buster-backports repository, APT will not install it automatically based on the priority. One would have to use apt install iptables/buster-backports or add a higher pinning priority to /etc/apt/preferences.d/iptables:

Package: iptables

Pin: release o=Debian Backports, a=buster-backports

Pin-Priority: 1001