第 2 章 Debian 软件包管理

目录

2.1. Debian 软件包管理的前提
2.1.1. 软件包配置
2.1.2. 基本的注意事项
2.1.3. 持续升级的生活
2.1.4. Debian 档案库基础
2.1.5. Debian 是100% 的自由软件
2.1.6. 软件包依赖关系
2.1.7. 包管理的事件流
2.1.8. 对包管理问题的第一个回应
2.2. 基础软件包管理操作
2.2.1. apt-get / apt-cache vs. aptitude
2.2.2. 命令行中的基础软件包管理操作
2.2.3. aptitude 的交互式使用
2.2.4. aptitude 的按键绑定
2.2.5. aptitude 软件包视图
2.2.6. aptitude 搜索方式选项
2.2.7. aptitude 正则表达式
2.2.8. aptitude 的依赖解决
2.2.9. 软件包活动日志
2.3. aptitude 操作范例
2.3.1. 通过正则表达式匹配软件包名称来列出软件包
2.3.2. 浏览正则表达式匹配
2.3.3. 完整地清理已删除软件包
2.3.4. 整理自动/手动安装状态
2.3.5. 全面的系统升级
2.4. 高级软件包管理操作
2.4.1. 命令行中的高级软件包管理操作
2.4.2. 验证安装的软件包文件
2.4.3. 预防软件包故障
2.4.4. 搜索软件包元数据
2.5. Debian 内部软件包管理
2.5.1. 档案库元数据
2.5.2. Top level "Release" file and authenticity
2.5.3. Archive level "Release" files
2.5.4. 获取用于软件包的元数据
2.5.5. APT 的软件包状态
2.5.6. aptitude 的软件包状态
2.5.7. 获取的软件包的本地副本
2.5.8. Debian 软件包文件名称
2.5.9. dpkg 命令
2.5.10. update-alternatives 命令
2.5.11. dpkg-statoverride 命令
2.5.12. dpkg-divert 命令
2.6. 从损坏的系统中恢复
2.6.1. 不兼容旧的用户配置
2.6.2. 具有相同文件的不同软件包
2.6.3. 修复损坏的软件包脚本
2.6.4. 使用 dpkg 命令进行救援
2.6.5. 恢复软件包选择数据
2.7. 软件包管理技巧
2.7.1. 如何挑选 Debian 软件包
2.7.2. 混合源档案库中的软件包
2.7.3. Tweaking candidate version
2.7.4. Updates and Backports
2.7.5. Blocking packages installed by "Recommends"
2.7.6. Tracking testing with some packages from unstable
2.7.7. Tracking unstable with some packages from experimental
2.7.8. 自动下载和升级软件包
2.7.9. 限制 APT 的下载带宽
2.7.10. Emergency downgrading
2.7.11. 上传软件包的是谁?
2.7.12. equivs 软件包
2.7.13. 移植一个软件包到 stable 系统
2.7.14. 用于 APT 的代理服务器
2.7.15. 小型公共软件包档案库
2.7.16. 记录和复制系统配置
2.7.17. 转换或安装一个外来的二进制软件包
2.7.18. 不使用 dpkg 解压软件包
2.7.19. 更多关于软件包管理的文档
[注意] 注意

这一章假定最新的稳定版的代号为:jessie

Debian 是一个志愿者组织,它建立一致的自由软件的预编译二进制包并从档案库中分发它们。

许多远程镜像站提供了 HTTP 和 FTP 的方式来访问 Debian 档案库。也可以使用 CD-ROM/DVD

Debian 软件包管理系统,当使用适当时,可以让用户从档案库安装统一设置的二进制软件包 到系统中。现在,有 54025 个可用于 amd64 架构的软件包。

Debian 软件包管理系统有丰富的历史,有许多可供选择的前端用户程序和后端访问方式。现在,我们推荐下列的这些。

表 2.1. Debian 软件包管理工具列表

软件包 流行度 大小 说明
apt V:869, I:999 3478 高级软件包工具(APT), dpkg 的前端,提供了 “http” 、“ftp” 和 “file” 的档案库访问方式(包含apt-getapt-cache 命令)
aptitude V:167, I:927 4449 aptitude(8) ,基于终端的交互式软件包管理工具
tasksel V:42, I:971 374 Debian 系统上对安装进行选择的工具(APT 的前端)
unattended-upgrades V:114, I:292 227 用于 APT 的增强软件包,会自动安装安全更新
dselect V:5, I:75 2486 基于终端的软件包管理工具(之前的标准,APT 的前端和其它老的访问方式)
dpkg V:929, I:999 6664 用于 Debian 的软件包管理系统
synaptic V:75, I:455 6930 图像化的软件包管理工具(GNOME 的 APT 前段)
apt-utils V:386, I:997 1093 APT 实用程序:apt-extracttemplates(1)apt-ftparchive(1)apt-sortpkgs(1)
apt-listchanges V:332, I:827 343 软件包历史更改提醒工具
apt-listbugs V:7, I:12 433 在每次 APT 安装前列出严重的 bug
apt-file V:13, I:78 82 APT 软件包搜索工具 —— 命令行界面
apt-rdepends V:0, I:6 65 递归列出软件包依赖

[警告] 警告

不要从任何的混合套件中安装软件包。它可能会打破软件包的一致性,这需要你要深厚的系统管理知识,例如 ABI 编译器、版本和解释器特性等等。

Debian 系统管理员中的新手应该保持在只进行安全更新的 stable 版本。我的意思是,最好避免下列的一些行为作为一项预防措施,直到你十分了解 Debian 系统。下面有一些提醒。

  • 在 “/etc/apt/sources.list” 中不要包含 testingunstable

  • 在 “/etc/apt/sources.list” 里不要在标准的 Debian 中混合使用其它非 Debian 的档案库,例如 Ubuntu 。

  • 不要建立 “/etc/apt/preferences” 。

  • 不了解会造成的全部影响,就不要通过配置文件改变软件包管理工具的默认行为。

  • 不要使用 “dpkg -i <random_package>” 安装任何软件包。

  • 绝不使用 “dpkg --force-all -i <random_package>” 安装任何软件包。

  • 不要删除或修改 “/var/lib/dpkg/” 中的文件。

  • 不要让从源码直接安装的程序覆盖系统文件。

    • 如果需要的话,将它们安装到 “/usr/local” 或 “/opt” 中。

上述对 Debian 软件包管理系统做的行为所导致的不兼容影响可能会使你的系统无法使用。

负责有关键任务的服务器的严谨的 Debian 系统系统管理员,应该使用额外的预防措施。

  • 没有在安全的条件下使用你特定的配置进行彻底地测试,就不要从 Debian 安装任何软件包(包含安全更新)。

    • 你作为系统管理员要对你的系统负责到底。

    • Debian 系统长久的稳定史并无法保证什么。

尽管我在上面进行了警告,我知道许多阅读这份文档的人还是想要使用 Debian 的 testingunstable 套件来作为他们自行管理的桌面环境的主系统。这是因为这些套件运行得很好,更新频繁,并提供了最新的特性。

[小心] 小心

对于你的生产服务器,建议使用带有安全更行的 stable 套件。对于你只进行有限管理的桌面 PC 也是同样如此,例如你母亲的 PC 。

你只需要在 “/etc/apt/sources.list” 中简单地将发行版字符串设置为套件名:“testing” 或 “unstable”;或者代号:“stretch” 或 “sid” 。这会使你享受持续升级的生活

使用 testingunstable很有乐趣的,但会带来一些风险。尽管 Debian 系统的 unstable 套件在大多数时候看起来都非常稳定,但在 Debian 系统的 testingunstable 套件中存在一些软件包问题,并且它们中的一部分是不容易解决的。这对你来说可能会很痛苦。有时候,你可能会有一个损坏的软件包或缺少某些功能几个星期。

这里有一些方法,可以使你简单快速地从 Debian 软件包的 bug 中恢复。

(如果你无法做到这些预防措施中的任何一个,那你可能还没做好使用 testingunstable 套件的准备。)

菩萨使用下面的内容拯救一个人,使他从挣扎于持续升级地狱因果报应中脱困,并让他达到 Debian 的极乐世界

让我们从系统用户的角度来看看 Debian 档案库

[提示] 提示

Debian 档案库官方政策的定义参见 Debian 政策文档,第2章 —— Debian 档案库

对于典型的 HTTP 访问,档案库在 “/etc/apt/sources.list” 文件中像下面那样指定,例如,现在 stable = jessie 系统。

deb http://deb.debian.org/debian/ jessie main contrib non-free
deb-src http://deb.debian.org/debian/ jessie main contrib non-free

deb http://security.debian.org/ jessie/updates main contrib
deb-src http://security.debian.org/ jessie/updates main contrib

这里,我倾向于使用代号 “jessie” 来代替套件名 “stable” ,以避免下一个 stable 版本发布时出现意外。

/etc/apt/sources.list” 的含义在 sources.list(5) 中进行了描述,下面是一些要点。

  • deb” 的那行定义了二进制软件包。

  • deb-src” 的那行定义了源代码软件包。

  • 第一个参数是 Debian 档案库的根 URL 。

  • 第二个参数是发行版名称:可以使用套件名或代号。

  • 第三个和之后的参数是 Debian 档案库的有效档案库范围名称。

deb-src” 的那行可以安全地删掉(或者在文件开头添加 “#” 来将它注释掉),如果它只是用于 aptitude (它不访问源代码相关的元数据)。这可以加速档案库元数据的更新。 URL 可以是 “http://” 、“ftp://” 、 “file://” ……

[提示] 提示

如果在上述的例子中,使用了 “sid” 代替 “jessie” ,那么 “/etc/apt/sources.list” 中的 “deb: http://security.debian.org/ …” 这行就不需要了。因为没有用于 “sid” (unstable)的安全更新的档案库。

下面是配置文件所使用的 Debian 档案库站点的 URL 和套件名或代号的列表。


[小心] 小心

只有带有安全更新的纯净的 stable release 版本可以提供最佳的稳定性。运行大多数 stable release 版本的软件包之中混合一些来自 testingunstable release 版本的软件包会比运行纯净的 unstable release 版本冒更大的风险,这是因为库版本的不匹配导致的。如果在 stable release 版本下你真的需要一些程序的最新版本,请使用来自 jessie-updateshttp://backports.debian.org (参见 第 2.7.4 节 “Updates and Backports”)的软件包。使用这些软件包时必须额外小心。

[小心] 小心

在 "deb" 行中,你只需列出 stabletesting 或者 unstable 套件中的一个即可,如果你在 "deb" 行中混合了 stabletestingunstable 套件,APT 程序的执行速度将会变慢并且只有最新的档案库是有用的。只有在 "/etc/apt/preferences" 文件带有明确目标的时候,混合的列表才是有意义的。(查看第 2.7.3 节 “Tweaking candidate version”

[提示] 提示

对于使用 stabletesting 套件的 Debian 系统而言,在 “/etc/apt/sources.list” 中包含带有 “http://security.debian.org/” 的一行是不错的主意。它会启用安全更新。

[注意] 注意

The security bugs for the stable archive are fixed by the Debian security team. This activity has been quite rigorous and reliable. Those for the testing archive may be fixed by the Debian testing security team. For several reasons, this activity is not as rigorous as that for stable and you may need to wait for the migration of fixed unstable packages. Those for the unstable archive are fixed by the individual maintainer. Actively maintained unstable packages are usually in a fairly good shape by leveraging latest upstream security fixes. See Debian security FAQ for how Debian handles security bugs.


上述软件包的数量是用于该amd64架构的。 main 区提供 Debian 系统(参见 第 2.1.5 节 “Debian 是100% 的自由软件”)。

Debian 档案包组织通过跟踪您所浏览的带 dists 或者 pool 标记的档案包 URL 获取相关信息从而做得更好。

发行版可以用套件或代号来指定。发行版在许多文档中也被当做是套件的同义词。套件和代号的关系总结如下。


代号的历史参见 Debian FAQ: 6.2.1 Which other codenames have been used in the past?

In the stricter Debian archive terminology, the word "section" is specifically used for the categorization of packages by the application area. (Although, the word "main section" may sometimes be used to describe the Debian archive area named as "main".)

Debian 开发者(DD)每次上传软件包到 unstable 档案库(通过 incoming 处理),都必须确保上传的软件包与最新的 unstable 档案库中的最新软件包兼容。

如果 DD 故意打破重要的库升级等的这种兼容性,这通常会在 Debian 开发者邮件列表等进行公告。

在 Debian 档案库维护脚本将软件包从 unstable 档案库移动到 testing 档案库前,档案库维护脚本不仅检查时间(约10天)和软件包的 RC bug 报告的状态,还尝试确保它们可以和最新的 testing 档案库中的软件兼容。这个过程使得testing 档案库非常正确可用。

Through the gradual archive freeze process led by the release team, the testing archive is matured to make it completely consistent and bug free with some manual interventions. Then the new stable release is created by assigning the codename for the old testing archive to the new stable archive and creating the new codename for the new testing archive. The initial contents of the new testing archive is exactly the same as that of the newly released stable archive.

unstabletesting 档案库都可能会遭受由以下几个因素导致的临时的小故障。

  • 损坏的软件包被上传到档案库(多见于 unstable

  • 延迟接受新的软件包到档案库(多见于 unstable )

  • 档案库时间同步问题( testingunstable

  • 手动干预档案库,例如移除软件包(多见于 testing )等。

因此,如果你决定使用这些档案库,你应该能够修复或忍受这些类型的小故障。

[小心] 小心

在新的 stable 版本发布后的几个月,大多数桌面用户应该使用带有安全更新的 stable 档案库,即使他们通常使用 unstabletesting 档案库。在这个过渡期中,unstabletesting 档案库不适合大多数人。你使用 unstable 档案库的系统是很难保持良好的工作状态的,因为它会遭受核心软件包的大量升级狂潮。 testing 档案库不大有用,因为它包含有和没有安全支持的 stable 档案库相同的内容(Debian testing 安全公告 2008-12)。一个月左右的时间后, 如果你仔细点的话, unstable 档案库或许可以使用。

[提示] 提示

跟踪 testing 档案库时,由一个已移除的软件包引起的问题通常可以安装 unstable 档案库中相同的软件包(已修复 bug )来解决。

档案库的定义参见 Debian 政策文档

Debian 是100%的自由软件,因为:

  • Debian 默认只安装自由软件,这尊重了用户的自由。

  • Debian 在 main 中只提供自由软件。

  • Debian 建议只运行来自 main 的自由软件。

  • main 中的软件包没有依赖于在 non-freecontrib 中的软件包。

有人想知道下列的两个事实是否互相矛盾。

因为下列原因,这并不矛盾。

  • Debian 系统具有100%的自由,并且它的软件包位于 Debian 服务器的 main 区域。

  • Debian 系统之外的软件包位于 Debian 服务器的 non-freecontrib 区域。

Debian 社群契约的第4条和第5条对这进行了明确的解释:

  • 我们将优先考虑我们的用户及自由软件

    • 我们由我们的用户及自由软件社群的需要所导向。我们将优先考虑他们的利益。我们将在多种计算环境中支持我们的用户的操作需要。我们不反对在 Debian 系统上使用非自由软件,我们也不会尝试向创建和使用这部分软件的用户索取费用。我们允许他人,在没有我们的资金的参与下,制造包括 Debian 以及商业软件的增值套件。为了达成这些目标,我们将提供集成的、高质量的、100%自由的软件,而不附加任何可能阻止在这些方面使用的法律限制。

  • 哪些作品不符合我们的自由软件规范

    • 我们明了,某些我们的用户需要使用不符合 Debian 自由软件指导方针的作品。 我们为这些作品,在我们的档案库中留出了 “contrib" 以及 “non-free" 目录。在这些目录下的软件包,并不属于 Debian 系统 尽管它们已被配置成可以在 Debian 下使用。我们鼓励光盘制造商阅读这些目录下的软件的许可证,以判断他们是否可以在光盘中发行这些软件 。所以,尽管非自由软件并非 Debian 系统的一部分,我们仍支持它们的使用,并且我们为非自由软件提供了公共资源 (诸如我们的缺陷跟踪系统以及邮件列表)。

用户应该了解使用 non-freecontrib 中的软件包所需要冒的风险:

  • 使用类似的软件包会失去自由

  • 失去 Debian 对软件包的支持(这些软件包无法访问源代码,Debian 不能进行完全的支持。)

  • 污染你100%自由的 Debian 系统

Debian 自由软件指导方针Debian 设立了自由软件标准。Debian 对软件包中的软件做了最广泛的解释,包含文档、固件、logo 和图形数据。这使得 Debian 的自由软件标准非常严格。

为了满足 main 严格的自由软件标准,Debian 提供了 去掉 Mozilla 商标 的软件包(例如 Firefox 、Thunderbird 和 Seamonkey),它们移除了 logo 和一些图形数据;并将它们分别用 Iceweasel 、Icedove 和 Iceape 替代。

典型的 non-freecontrib 软件包包含了下列类型的自由分发的软件包:

  • GNU Free Documentation License下的文档包 ,包含不变的部分 ,比如GCC 和 Make的。 (大多数都可以在non-free/doc找到 .)

  • 包含没有源代码的二进制数据的固件软件包,例如在 第 9.9.6 节 “硬件驱动和固件” 中列出的 non-free 软件包。(多见于 non-free/kernel 部分。)

  • 游戏和字体软件包,对商业使用和/或内容修改进行了限制。

请注意,non-freecontrib 软件包的数量少于 main 软件包的2%。允许访问 non-freecontrib 并不会模糊软件包的来源。使用 aptitude(8) 的全屏交互式界面可以提供完全的可见性和完全的控制,可以让你决定安装来自某个部分的软件包,来使你的系统保持自由。

The Debian system offers a consistent set of binary packages through its versioned binary dependency declaration mechanism in the control file fields. Here is a bit over simplified definition for them.

  • “依赖”

    • 绝对的依赖,所有在这里列出的软件包都必须同时或提前安装。

  • "Pre-Depends"

    • 类似于 Depends,但列出的软件包必须提前完成安装。

  • “推荐”

    • This declares a strong, but not absolute, dependency. Most users would not want the package unless all of the packages listed in this field are installed.

  • “建议”

    • 较弱的依赖。这个软件包的大多数用户可能会从安装所列的软件包中受益,但没有它们也可以有适当的功能。

  • ”增强“

    • 这里表明一个像推荐的弱依赖关系,不装也没关系。

  • ”破损“

    • 表明一个软件包不兼容一些版本规范。一般的解决方法就是升级列出的所有软件包。

  • ”冲突“

    • 这表明了绝对的不兼容。为了安装这个软件包必须移除所有列出的软件包。

  • ”替代“

    • 这表明这个文件安装的文件会替代所列的软件包的文件。

  • ”提供“

    • 表明这个软件包会提供所列的软件包所有的文件和功能。

[注意] 注意

请注意,同时将 “Provides” 、“Conflicts” 和 “Replaces” 定义到一个虚拟的软件包是一个明智的配置。这确保了在任何一个时间只能安装一个提供该虚拟包的真正软件包。

包含源代码依赖关系的官方定义位于 the Policy Manual: Chapter 7 - Declaring relationships between packages

这是 APT 提供的软件包管理的简单事件流摘要。

Here, I intentionally skipped technical details for the sake of big picture.

在 Debian 系统中有许多基于 ATP 的软件包管理工具可以在 Debian 系统上进行基于仓库的软件包管理操作。在这里,我们将介绍两种基本的软件包管理工具:apt-get / apt-cacheaptitude

对于涉及软件包安装或更新软件包元数据的软件包管理操作,你必须有 root 权限。

尽管 aptitude 是作者主要使用的一个非常好的可互动工具,但你应该知道下列警示:

apt-getapt-cache 是最 基础 的基于 APT 的软件包管理工具。

  • apt-getapt-cache 只提供命令行用户界面。

  • apt-get 是进行跨版本的主系统升级等操作的最合适工具。

  • apt-get 提供了一个强大的软件包依赖解析器。

  • apt-get 对硬件资源的要求不高。它消耗更少的内存并且运行速度更快。

  • apt-cache 提供了一个 标准的正则表达式来搜索软件包名称和描述。

  • apt-getapt-cache 可以使用 etc/apt/preferences 来管理软件包的多个版本,但这非常繁琐。

aptitude 命令是最通用的基于 APT 的软件包管理工具。

  • aptitude 提供了一个全屏的交互式文本用户界面。

  • aptitude 同样也提供了一个命令用户界面。

  • aptitude 是用于日常软件包管理(例如检查已安装的软件包和搜索可用的软件包)的最合适工具。

  • aptitude 对硬件资源的要求更高。它消耗更多的内存并且运行速度更慢。

  • aptitude 提供一个增强的正则表达式来搜索所有的软件包元数据。

  • aptitude 可以管理软件包的多个版本,并且不使用 /etc/apt/preferences,这会十分直观。

下面是使用 aptitude(8)apt-get(8) / apt-cache(8) 的命令行基本软件包管理操作。


[注意] 注意

Although the aptitude command comes with rich features such as its enhanced package resolver, this complexity has caused (or may still causes) some regressions such as Bug #411123, Bug #514930, and Bug #570377. In case of doubt, please use the apt-get and apt-cache commands over the aptitude command.

[注意] 注意

因为在 lenny 版本之后的 Debian 系统中,apt-getaptitude 会共享自动安装的软件包的状态(参见第 2.5.5 节 “APT 的软件包状态”),因此你可以混合使用这些工具而不会出现严重的麻烦(参见 Bug #594490)。

aptitude why <regex>” 可以通过 “aptitude -v why <regex>” 列出更多的信息。类似的信息可以通过 “apt-cache rdepends <package>” 获取。

aptitude 命令在命令行模式下启动后遇到了一些问题(例如软件包冲突),你可以在之后的提示中按下 “e” 键切换到全屏的交互模式。

你可以在 “aptitude” 后面使用的命令选项。


更多内容参见 aptitude(8) 和位于 “/usr/share/doc/aptitude/README” 的 “aptitude 用户手册”。

[提示] 提示

dselect 软件包依旧可用,并且曾是之前发布的版本中首选的全屏交互式软件包管理工具。

aptitude(8) 全屏交互模式下,软件包列表里的软件包会像下面的例子那样显示。

idA   libsmbclient                             -2220kB 3.0.25a-1  3.0.25a-2

该行的从左到右的含义如下。

  • “状态”标签 (第一个字母)

  • “动作”标签(第二个字母)

  • “自动”标签(第三个字母)

  • 软件包名称

  • 该“动作”对磁盘空间的变化

  • 软件包当前版本

  • 软件包可用版本

[提示] 提示

您可以在帮助菜单中找到完整的标签列表,按“?”即可在帮助菜单底部显示。

可用版本 的选择是依据当前的本地首选项(参见 apt_preferences(5)第 2.7.3 节 “Tweaking candidate version”)。

软件包视图的几种类型都可以在“ 视图 ”菜单下找到。


标准“软件包视图”分类软件包的方法与带有一些额外功能的 dselect 有点像。


[提示] 提示

软件集视图可以用来为你的任务选出最佳的软件包。

aptitude 正则表达式是类 mutt 的拓展 ERE(参见 第 1.6.2 节 “正则表达式”),aptitude 具体的特殊匹配规则扩展如下。

表 2.11. aptitude 正则表达式

扩展匹配规则描述 正则表达式
匹配软件包名称 ~n<regex_name>
匹配描述 ~d<regex_description>
匹配软件集名称 ~t<regex_task>
匹配 debtag ~G<regex_debtag>
匹配维护者 ~m<regex_maintainer>
match on package section ~s<regex_section>
匹配软件包版本 ~V<regex_version>
匹配档案库 ~A{jessie,stretch,sid}
匹配来源 ~O{debian,…}
匹配优先级 ~p{extra,important,optional,required,standard}
匹配必要的软件包 ~E
匹配虚拟软件包 ~v
匹配新的软件包 ~N
匹配待执行的动作 ~a{install,upgrade,downgrade,remove,purge,hold,keep}
匹配已安装软件包 ~i
匹配带有 A 标签的已安装软件包(自动安装的软件包) ~M
匹配不带有 A 标签的已安装软件包(管理员选择的软件包) ~i!~M
匹配已安装和可升级软件包 ~U
匹配已删除但未清除的软件包 ~c
匹配已移除,已清除或可移除的软件包 ~g
匹配破坏依赖关系的软件包 ~b
匹配破坏 <type> 依赖关系的软件包 ~B<类型>
匹配 <pattern> 软件包的 <type> 依赖关系 ~D[<类型>:]<模式>
匹配 <pattern> 软件包破坏的 <type> 依赖关系 ~DB[<类型>:]<模式>
匹配依赖于 <pattern> 软件包的 <type> 依赖的软件包 ~R[<类型>:]<模式>
匹配依赖于 <pattern> 软件包破坏的 <type> 依赖的软件包 ~RB[<类型>:]<模式>
匹配其它已安装软件包所依赖的软件包 ~R~i
匹配没有被其它已安装软件包所依赖的软件包 !~R~i
匹配其它已安装软件包所依赖或建议安装的软件包 ~R~i|~R推荐:~i
匹配 <pattern> 过滤版本之后的软件包 ~S 过滤 <模式>
匹配所有软件包(真) ~T
不匹配软件包(假) ~F

  • The regex part is the same ERE as the one used in typical Unix-like text tools using "^", ".*", "$" etc. as in egrep(1), awk(1) and perl(1).

  • 依赖关系 <type> 是一种特定的软件包相互关系(depends、predepends、recommends、suggests、conflicts、replaces、provides)。

  • 默认的 <type> 依赖关系是 “depends”。

[提示] 提示

当 <regex_pattern> 为空字符串时,请立即在命令后面添加 "~T"。

下面是一些快捷方式。

  • "~P<term>" == "~Dprovides:<term>"

  • "~C<term>" == "~Dconflicts:<term>"

  • "…~W term" == "(…|term)"

用户熟悉 mutt 的快速选择,因为 mutt 的灵感来源于表达式语法。参见 “用户手册” “/usr/share/doc/aptitude/README” 中的 “SEARCHING, LIMITING, AND EXPRESSIONS”。

[注意] 注意

With the lenny version of aptitude(8), the new long form syntax such as "?broken" may be used for regex matching in place for its old short form equivalent "~b". Now space character " " is considered as one of the regex terminating character in addition to tilde character "~". See "User's Manual" for the new long form syntax.

下面是一些 aptitude(8) 的操作范例。

Here is how I tidy auto/manual install status for packages (after using non-aptitude package installer etc.).

  1. 用 root 以交互模式运行 aptitude

  2. 用 "u" 命令更新可用的软件包列表,"U" 命令标记所有可升级的软件包以执行升级,"f" 命令清除新软件包列表,"g" 命令执行所有可升级的软件包以执行升级。

  3. Type "l" to enter the package display limit as "~i(~R~i|~Rrecommends:~i)" and type "M" over "Installed Packages" as auto installed.

  4. Type "l" to enter the package display limit as "~prequired|~pimportant|~pstandard|~E" and type "m" over "Installed Packages" as manual installed.

  5. Type "l" to enter the package display limit as "~i!~M" and remove unused package by typing "-" over each of them after exposing them by typing "[" over "Installed Packages".

  6. 输入 "l", 来过滤软件包 "~i"; 然后输入 "m" 上面 "Tasks", 来手动标记安装软件包。.

  7. 退出 aptitude

  8. 用 root 用户执行 "apt-get -s autoremove|less" 命令,来查看有那些软件包是不再需要的。

  9. 在交互模式下重启 aptitude 程序,用 “m” 命令标记所需要的软件包。

  10. 用 root 用户重新执行 "apt-get -s autoremove|less" 这个命令来复查移除的包中是不是只含有自己所希望移除的软件包。

  11. 用 root 用户执行 "apt-get autoremove|less" 命令来自动移除不再需要的软件包。

在你所需要执行的 "Tasks" 上,运行 "m" 命令是一个可选的操作,目的就是为了防止大量软件包被卸载的情况出现。

[注意] 注意

当你迁移到新的发行版的时候,虽然正如下面所描述的那样,Debian 是可升级的,但是你还是应该考虑纯净的安装新的系统。这给了你机会去移除废弃的软件包同时还可以接触到最新软件包的完美集合体。当然,在做迁移之前,你也应该对你的系统做完整的备份,并把它移到安全的地方去(查看第 10.2 节 “备份和恢复”)。“我”也建议用不同的分区做另外一个启动项,来实现平稳的升级。

你可以通过改变 "/etc/apt/sources.list" 的内容使之指向新的发行版所在地址的方法来进行系统的全面升级,然后运行 "apt-get update; apt-get dist-upgrade" 命令。

stable 升级到 testing 或者 unstable,你应该用 "stretch" 或者 "sid" 替换 "/etc/apt/sources.list" 文件里的 "jessie",参考 第 2.1.4 节 “Debian 档案库基础”

事实上,由于一些软件包版本变迁的问题,你可能会遇到一些困难,主要是由于软件包的依赖问题。升级之后的差异越大,你越有可能遇到麻烦。在新版本发行后,系统从旧的 stable 过渡到新的 stable,你可以查看 Release Notes 然后按照里面的步骤去做,来尽可能的减少麻烦。

在它正式发布之前,你决定要从先前的 stable 迁移到将要发布的 testing,这里没有 Release Notes 可以帮到你。 在前一个 stable 发布以后, stable 发行版跟将要发布的 testing 发行版之间的差异可能变得相当大同时也使得升级系统变得更加的复杂。

在全面升级系统的时候,你应该谨慎的操作,同时你也应该从邮件列表中获取最新的资料然后根据你的常识作出正确的判断。

  1. 查看先前的“发行说明”。

  2. 备份整个系统(尤其是数据和配置信息)。

  3. 当 bootloader 坏了的时候,手边应该有可以引导电脑启动的存储介质。

  4. 事先通知系统上的用户。

  5. script(1) 记录升级的过程。

  6. 用 “unmarkauto” 命令来保留你想要的软件包,例如 "aptitude unmarkauto vim" 这个命令是用来防止移除vim这个软件的。

  7. 为了减少软件包之间可能会发生的冲突,应该尽量减少要安装的软件包的数目,例如,移除桌面环境这个软件包。

  8. 移除 "/etc/apt/preferences" 文件(禁用apt-pinning)。

  9. 试着一步步的升级: oldstablestabletestingunstable.

  10. 升级 "/etc/apt/sources.list" 文件,使其指向新的档案库然后运行 "aptitude update" 命令。

  11. 可选的安装选项,首先是新的 core packages,例如 “aptitude install perl"。

  12. 运行 "apt-get -s dist-upgrade" 命令来评估升级造成的影响。

  13. 最后运行 "apt-get dist-upgrade" 命令。

[小心] 小心

stable 版本升级的时候,跳过主要的 Debian 发行版是不明智的。

[小心] 小心

在先前的“发行手册”里, GCC, Linux Kernel, initrd-tools, Glibc, Perl, APT tool chain等等,有一些关于系统全面升级的重要注意事项。

关于 unstable 版本的日常升级,查看 第 2.4.3 节 “预防软件包故障”

下面列出了一些其它的软件包管理操作,这些操作对于 aptitude 过于高级或缺失所需的功能。

表 2.13. 高级软件包管理操作

命令 操作
COLUMNS=120 dpkg -l <package_name_pattern> 列出已安装软件包的列表用于错误报告
dpkg -L <package_name> 显示一个已安装软件包的内容
dpkg -L <package_name> | egrep '/usr/share/man/man.*/.+' 列出一个已安装软件包的 man 手册页
dpkg -S <file_name_pattern> 列出匹配文件名的已安装软件包
apt-file search <file_name_pattern> 列出档案库中匹配文件名的软件包
apt-file list <package_name_pattern> 列出档案库中匹配的软件包的内容
dpkg-reconfigure <package_name> 重新配置软件包
dpkg-reconfigure -p=low <package_name> reconfigure the exact package with the most detailed question
configure-debian 以全屏菜单的形式重新配置软件包
dpkg --audit audit system for partially installed packages
dpkg --configure -a configure all partially installed packages
apt-cache policy <binary_package_name> 显示一个二进制软件包的可用版本、优先级和档案库信息
apt-cache madison <package_name> 显示一个软件包的可用版本和档案库信息
apt-cache showsrc <binary_package_name> 显示一个二进制软件包的源代码软件包信息
apt-get build-dep <package_name> 安装构建软件包所需要的软件包
aptitude build-dep <package_name> 安装构建软件包所需要的软件包
apt-get source <package_name> (从标准档案库)下载源代码
dget <URL for dsc file> (从其它档案库)下载源代码软件包
dpkg-source -x <package_name>_<version>-<debian_version>.dsc build a source tree from a set of source packages ("*.orig.tar.gz" and "*.debian.tar.gz"/"*.diff.gz")
debuild binary 从本地的源代码树中构建软件包
make-kpkg kernel_image 从内核源代码树中构建一个内核软件包
make-kpkg --initrd kernel_image build a kernel package from a kernel source tree with initramfs enabled
dpkg -i <package_name>_<version>-<debian_version>_<arch>.deb 安装一个本地的软件包到系统中
debi <package_name>_<version>-<debian_version>_<arch>.dsc 安装本地软件包到系统中
dpkg --get-selections '*' >selection.txt save dpkg level package selection state information
dpkg --set-selections <selection.txt set dpkg level package selection state information
echo <package_name> hold | dpkg --set-selections set dpkg level package selection state for a package to hold (equivalent to "aptitude hold <package_name>")

[注意] 注意

对于一个支持多架构的软件包,你可能需要为一些命令指定架构名称。例如,使用 “dpkg -L libglib2.0-0:amd64” 来列出 amd64 架构的 libglib2.0-0 软件包的内容。

[小心] 小心

系统管理员应该小心使用低级的软件包工具(例如 “dpkg -i …” 和 “debi …”),它们不会自动处理所需的软件包依赖。 dpkg 的命令行选项 “--force-all” 和类似的选项(参见 dpkg(1))只适用于高手。没有完全理解它们的效果却使用它们会破坏你的整个系统。

请注意以下几点。

The installation of debsums enables verification of installed package files against MD5sum values in the "/var/lib/dpkg/info/*.md5sums" file with debsums(1). See 第 10.3.5 节 “The MD5 sum” for how MD5sum works.

[注意] 注意

Because MD5sum database may be tampered by the intruder, debsums(1) is of limited use as a security tool. It is only good for checking local modifications by the administrator or damage due to media errors.

尽管近来浏览 Debian 网站 http://packages.debian.org/ 是搜索软件包元数据更加简单的方法,但我们依旧来看看更传统的方法。

grep-dctrl(1)grep-status(1)grep-available(1) 命令被用来搜索具有 Debian 软件包控制文件格式的任何文件。

dpkg -S <file_name_pattern>” 被用来搜索由 dpkg 安装的软件包中包含匹配文件的。但它会忽略维护者的脚本创建的文件。

如果你需要对 dpkg 元数据进行更复杂的搜索,你需要在 “/var/lib/dpkg/info/” 目录下运行 “grep -e regex_pattern *” 命令。这会使你在软件包脚本和安装查询文本中搜索提及的单词。

如果你想递归查找软件包依赖,你应该使用 apt-rdepends(8)

让我们来学习 Debian 软件包管理的内部工作原理。这应该能够帮助你独立解决一些软件包问题。

[提示] 提示

The top level "Release" file is used for signing the archive under the secure APT system.

每个 Debian 档案库的网址都有一个这样的 “Release” 文件,例如 “http://deb.debian.org/debian/dists/unstable/Release”,内容如下。

Origin: Debian
Label: Debian
Suite: unstable
Codename: sid
Date: Sat, 14 May 2011 08:20:50 UTC
Valid-Until: Sat, 21 May 2011 08:20:50 UTC
Architectures: alpha amd64 armel hppa hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 sparc
Components: main contrib non-free
Description: Debian x.y Unstable - Not Released
MD5Sum:
 bdc8fa4b3f5e4a715dd0d56d176fc789 18876880 Contents-alpha.gz
 9469a03c94b85e010d116aeeab9614c0 19441880 Contents-amd64.gz
 3d68e206d7faa3aded660dc0996054fe 19203165 Contents-armel.gz
...
[注意] 注意

Here, you can find my rationale to use the "suite", and "codename" in 第 2.1.4 节 “Debian 档案库基础”. The "distribution" is used when referring to both "suite" and "codename". All archive "area" names offered by the archive are listed under "Components".

The integrity of the top level "Release" file is verified by cryptographic infrastructure called the secure apt.

  • The cryptographic signature file "Release.gpg" is created from the authentic top level "Release" file and the secret Debian archive key.

  • The public Debian archive key can be seeded into "/etc/apt/trusted.gpg";

  • The secure APT system verifies the integrity of the downloaded top level "Release" file cryptographically by this "Release.gpg" file and the public Debian archive key in "/etc/apt/trusted.gpg".

The integrity of all the "Packages" and "Sources" files are verified by using MD5sum values in its top level "Release" file. The integrity of all package files are verified by using MD5sum values in the "Packages" and "Sources" files. See debsums(1) and 第 2.4.2 节 “验证安装的软件包文件”.

Since the cryptographic signature verification is a much more CPU intensive process than the MD5sum value calculation, use of MD5sum value for each package while using cryptographic signature for the top level "Release" file provides the good security with the performance (see 第 10.3 节 “Data security infrastructure”).

When APT tools, such as aptitude, apt-get, synaptic, apt-file, auto-apt, … are used, we need to update the local copies of the meta data containing the Debian archive information. These local copies have following file names corresponding to the specified distribution, area, and architecture names in the "/etc/apt/sources.list" (see 第 2.1.4 节 “Debian 档案库基础”).

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_<distribution>_Release"

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_<distribution>_Release.gpg"

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_<distribution>_<area>_binary-<architecture>_Packages"

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_<distribution>_<area>_source_Sources"

  • "/var/cache/apt/apt-file/deb.debian.org_debian_dists_<distribution>_Contents-<architecture>.gz" (for apt-file)

前4中类型的文件是所有相关的 APT 命令共享的,并且可以通过 “apt-get update” 或 “aptitude update” 在命令行中进行更新。如果在 “/etc/apt/sources.list” 中有相应的 “deb” 行,则 “软件包” 元数据会进行更新。如果在 “/etc/apt/sources.list” 中有相应的 “deb-src” 行,则 “源代码” 元数据会进行更新。

The "Packages" and "Sources" meta data contain "Filename:" stanza pointing to the file location of the binary and source packages. Currently, these packages are located under the "pool/" directory tree for the improved transition over the releases.

软件包”元数据的本地副本可以使用 aptitude 来进行交互式的搜索。专门的搜索命令 grep-dctrl(1) 可以搜索“软件包”和“源代码”元数据的本地副本。

Local copy of "Contents-<architecture>" meta data can be updated by "apt-file update" and its location is different from other 4 ones. See apt-file(1). (The auto-apt uses different location for local copy of "Contents-<architecture>.gz" as default.)

Debian 软件包文件有特定的名称结构。


[提示] 提示

Here only the basic source package formats are described. See more on dpkg-source(1).


[注意] 注意

你可以用 dpkg(1)提供的命令检查软件包版本, 例如., "dpkg --compare-versions 7.0 gt 7.~pre1 ; echo $?" .

[注意] 注意

debian-installer (d-i) 使用 udeb 作为它的二进制软件包的文件扩展名,而非普通的 deb。一个 udeb 软件包是从 deb 软件包中剥离了一些不必要的内容(例如文档),从而节省空间同时也放宽软件包政策的要求。debudeb 软件包会共享相同的软件包结构。“u” 表示微小。

dpkg(1) 是 Debian 软件包管理中最底层的工具。它非常强大,必须小心使用。

当安装名为 “<package_name>” 的软件包时,dpkg 会按照下列的顺序处理它。

  1. 解包 deb 文件(等同于 “ar -x”)

  2. 使用 debconf(1) 执行 “<package_name>.preinst

  3. 将软件包安装到系统中(等同于 “tar -x”)

  4. 使用 debconf(1) 执行 “<package_name>.postinst

debconf 系统提供带有 I18N 和 L10N (第 8 章 I18N 和 L10N)支持的标准化用户交互。


status” 文件也被例如 dpkg(1)、“dselect update” 和 “apt-get -u dselect-upgrade” 等工具使用。

专门的搜索命令 grep-dctrl(1) 可以搜索 “status” 和 “available” 元数据的本地副本。

[提示] 提示

In the debian-installer environment, the udpkg command is used to open udeb packages. The udpkg command is a stripped down version of the dpkg command.

When running unstable system, the administrator is expected to recover from broken package management situation.

[小心] 小心

下面的一些方法具有很高的风险。在此先对你进行警告!

Archive level package management systems, such as aptitude(8) or apt-get(1), do not even try to install packages with overlapped files using package dependencies (see 第 2.1.6 节 “软件包依赖关系”).

Errors by the package maintainer or deployment of inconsistently mixed source of archives (see 第 2.7.2 节 “混合源档案库中的软件包”) by the system administrator may create a situation with incorrectly defined package dependencies. When you install a package with overlapped files using aptitude(8) or apt-get(1) under such a situation, dpkg(1) which unpacks package ensures to return error to the calling program without overwriting existing files.

[小心] 小心

使用第三方软件包会导致重大的系统风险,因为其通过使用 root 权限运行维护者脚本能够对你的系统做任何事。dpkg(1) 命令只防止解包时的覆盖行为。

You can work around such broken installation by removing the old offending package, <old-package>, first.

$ sudo dpkg -P <old-package>

因为 dpkg 是非常底层的软件包工具,它可以在很糟糕的情况下进行工作,例如无法启动系统且没有网络连接。让我们假定 foo 软件包损坏了,并且需要更换。

你可以在软件包缓存目录:“/var/cache/apt/archives/” 中找到旧的 foo 软件包的无 bug 版本。(如果找不到,你可以从档案库 http://snapshot.debian.net/ 中下载它,或从具有软件包缓存功能的机器中拷贝它。)

如果你能够启动系统,你可以通过下列命令来安装它。

# dpkg -i /path/to/foo_<old_version>_<arch>.deb
[提示] 提示

如果你系统损坏较小,你也可以使用更高层的 APT 系统来降级整个系统,就像 第 2.7.10 节 “Emergency downgrading” 中做的那样。

如果你的系统无法从硬盘启动,你应该寻找其它方式来启动它。

  1. 使用 Debian 安装光盘以救援模式启动系统。

  2. 将硬盘上无法启动的系统挂载到 “/target”。

  3. 通过下列命令安装旧版本的 foo 软件包。

# dpkg --root /target -i /path/to/foo_<old_version>_<arch>.deb

即使位于硬盘上的 dpkg 命令已损坏,该命令依旧可以执行。

[提示] 提示

任何由硬盘、live GNU/Linux CD、可启动的 USB 驱动或网络启动上的另一系统启动的 GNU/Linux 系统到可以类似地用来救援损坏的系统。

如果由于依赖问题,无法用这种方式安装软件包,并且你真的必须真么做,你可以使用 dpkg 的 “--ignore-depends”、“--force-depends” 和其它选项来无视依赖。如果你这么做了,之后你必须认真努力地修复依赖关系。更多细节参见 dpkg(8)

[注意] 注意

如果你的系统严重损坏了,你应该将系统完整备份到一个安全的地方(参见 第 10.2 节 “备份和恢复”)并进行一次全新的安装。这是耗时较少且效果较好的办法。

[小心] 小心

从混合源档案库中安装软件包是不被 Debian 官方发行版所支持的,除了官方支持的档案库的特殊组合以外,例如 stable with security updates and jessie-updates

Here is an example of operations to include specific newer upstream version packages found in unstable while tracking testing for single occasion.

  1. 临时更改 "/etc/apt/sources.list" 文件,使之指向单一的 "unstable" 发行版路径。

  2. 运行 "aptitude update" 命令。

  3. 运行 "aptitude install <package-name>" 命令。

  4. 恢复到原始 "/etc/apt/sources.list" 文件,使之指向 testing 路径。

  5. 运行 "aptitude update" 命令。

You do not create the "/etc/apt/preferences" file nor need to worry about apt-pinning with this manual approach. But this is very cumbersome.

[小心] 小心

当使用混合档案源的时候,因为 Debian 不会确保软件之间的兼容性,所以你必须自己去解决兼容性问题。如果软件之间存在不兼容性,系统可能会损坏。你必须能够判断这些操作所需的技术要求。使用任意混合的档案源是完全可选的操作,我并不鼓励你去使用它。

从不同的档案库中安装软件包的一般规则如下。

[注意] 注意

为了使软件包的安装变得更保险 ,一些商业的非自由的二进制程序包可能会提供完整的静态链接库。你还是应该检查 ABI 的兼容性问题等等。

[注意] 注意

Except to avoid broken package for a short term, installing binary packages from officially unsupported archives is generally bad idea. This is true even if you use apt-pinning (see 第 2.7.3 节 “Tweaking candidate version”). You should consider chroot or similar techniques (see 第 9.10 节 “虚拟化系统”) to run programs from different archives.

Without the "/etc/apt/preferences" file, APT system choses the latest available version as the candidate version using the version string. This is the normal state and most recommended usage of APT system. All officially supported combinations of archives do not require the "/etc/apt/preferences" file since some archives which should not be used as the automatic source of upgrades are marked as NotAutomatic and dealt properly.

[提示] 提示

The version string comparison rule can be verified with, e.g., "dpkg --compare-versions ver1.1 gt ver1.1~1; echo $?" (see dpkg(1)).

When you install packages from mixed source of archives (see 第 2.7.2 节 “混合源档案库中的软件包”) regularly, you can automate these complicated operations by creating the "/etc/apt/preferences" file with proper entries and tweaking the package selection rule for candidate version as described in apt_preferences(5). This is called apt-pinning.

[警告] 警告

Use of apt-pinning by a novice user is sure call for major troubles. You must avoid using apt-pinning except when you absolutely need it.

[小心] 小心

When using apt-pinning, you must ensure compatibility of packages by yourself since the Debian does not guarantee it. The apt-pinning is completely optional operation and its use is not something I encourage you to use.

[小心] 小心

Archive level Release files (see 第 2.5.3 节 “Archive level "Release" files”) are used for the rule of apt_preferences(5). Thus apt-pinning works only with "suite" name for normal Debian archives and security Debian archives. (This is different from Ubuntu archives.) For example, you can do "Pin: release a=unstable" but can not do "Pin: release a=sid" in the "/etc/apt/preferences" file.

[小心] 小心

When you use non-Debian archive as a part of apt-pinning, you should check what they are intended for and also check their credibility. For example, Ubuntu and Debian are not meant to be mixed.

[注意] 注意

Even if you do not create the "/etc/apt/preferences" file, you can do fairly complex system operations (see 第 2.6.4 节 “使用 dpkg 命令进行救援” and 第 2.7.2 节 “混合源档案库中的软件包”) without apt-pinning.

Here is a simplified explanation of apt-pinning technique.

The APT system choses the highest Pin-Priority upgrading package from available package sources defined in the "/etc/apt/sources.list" file as the candidate version package. If the Pin-Priority of the package is larger than 1000, this version restriction for upgrading is dropped to enable downgrading (see 第 2.7.10 节 “Emergency downgrading”).

Pin-Priority value of each package is defined by "Pin-Priority" entries in the "/etc/apt/preferences" file or uses its default value.


The target release archive can be set by several methods.

  • "/etc/apt/apt.conf" configuration file with "APT::Default-Release "stable";" line

  • command line option, e.g., "apt-get install -t testing some-package"

The NotAutomatic and ButAutomaticUpgrades archive is set by archive server having its archive level Release file (see 第 2.5.3 节 “Archive level "Release" files”) containing both "NotAutomatic: yes" and "ButAutomaticUpgrades: yes". The NotAutomatic archive is set by archive server having its archive level Release file containing only "NotAutomatic: yes".

The apt-pinning situation of <package> from multiple archive sources is displayed by "apt-cache policy <package>".

  • A line started with "Package pin:" lists the package version of pin if association just with <package> is defined, e.g., "Package pin: 0.190".

  • No line with "Package pin:" exists if no association just with <package> is defined.

  • The Pin-Priority value associated just with <package> is listed right side of all version strings, e.g., "0.181 700".

  • "0" is listed right side of all version strings if no association just with <package> is defined, e.g., "0.181 0".

  • The Pin-Priority values of archives (defined as "Package: *" in the "/etc/apt/preferences" file) are listed left side of all archive paths, e.g., "100 http://deb.debian.org/debian/ jessie-backports/main Packages".

jessie-updatesbackports.debian.org 档案库提供了stable (jessie) 发行版的更新软件包。

为了去使用这些档案库,你需要在 "/etc/apt/sources.list" 文件里写入如下所示的档案库列表。

deb http://deb.debian.org/debian/ jessie main contrib non-free
deb http://security.debian.org/ jessie/updates main contrib
deb http://deb.debian.org/debian/ jessie-updates main contrib non-free
deb http://deb.debian.org/debian/ jessie-backports main contrib non-free

There is no need to set Pin-Priority value explicitly in the "/etc/apt/preferences" file. When newer packages become available, the default configuration provides most reasonable upgrades (see 第 2.5.3 节 “Archive level "Release" files”).

  • 所有已安装的旧软件包都可以通过 jessie-updates 档案库升级到新软件包。

  • 只有从 jessie-backports 档案库中手动安装的旧软件包才会通过 jessie-backports 档案库升级到新软件包。

当你想要从 jessie-backports 档案库中手动的安装一个名叫 "<package-name>" 的软件及其依赖包的时候,你应该在目标档案库之前加一个 “-t" 参数。

$ sudo apt-get install -t jessie-backports <package-name>

Here is an example of apt-pinning technique to include specific newer upstream version packages found in unstable regularly upgraded while tracking testing. You list all required archives in the "/etc/apt/sources.list" file as the following.

deb http://deb.debian.org/debian/ testing main contrib non-free
deb http://deb.debian.org/debian/ unstable main contrib non-free
deb http://security.debian.org/ testing/updates main contrib

Set the "/etc/apt/preferences" file as as the following.

Package: *
Pin: release a=unstable
Pin-Priority: 100

When you wish to install a package named "<package-name>" with its dependencies from unstable archive under this configuration, you issue the following command which switches target release with "-t" option (Pin-Priority of unstable becomes 990).

$ sudo apt-get install -t unstable <package-name>

在此配置下,执行 "apt-get update" 和 "apt-get dist-upgrade"(或者 "aptitude safe-upgrade" 和 "aptitude full-upgrade") 命令,会从 testing 档案库升级那些从 testing 档案库安装的软件包并且从 unstable 档案库升级那些从 unstable 档案库中安装的软件包。

[小心] 小心

小心不要去移除 "/etc/apt/sources.list" 文件中的 "testing" 档案库。如果文件中没有 "testing" ,APT 系统会使用更加新的 unstable 档案库升级软件包。

[提示] 提示

我通常会在上述操作后,马上注释掉 "/etc/apt/sources.llist" 文件中的 "unstable" 档案库记录。这避免了因为处理 "/etc/apt/sources.list" 文件中的众多记录而造成的升级缓慢虽然同时也阻止了那些从 unstable 档案库中安装的软件包通过 unstable 升级。

[提示] 提示

If "Pin-Priority: 1" is used instead of "Pin-Priority: 100" in the "/etc/apt/preferences" file, already installed packages having Pin-Priority value of 100 are not upgraded by unstable archive even if "testing" entry in the "/etc/apt/sources.list" file is removed.

If you wish to track particular packages in unstable automatically without initial "-t unstable" installation, you must create the "/etc/apt/preferences" file and explicitly list all those packages at the top of it as the following.

Package: <package-1>
Pin: release a=unstable
Pin-Priority: 700

Package: <package-2>
Pin: release a=unstable
Pin-Priority: 700

These set Pin-Priority value for each specific package. For example, in order to track the latest unstable version of this "Debian Reference" in English, you should have following entries in the "/etc/apt/preferences" file.

Package: debian-reference-en
Pin: release a=unstable
Pin-Priority: 700

Package: debian-reference-common
Pin: release a=unstable
Pin-Priority: 700
[提示] 提示

This apt-pinning technique is valid even when you are tracking stable archive. Documentation packages have been always safe to install from unstable archive in my experience, so far.

[小心] 小心

Downgrading is not officially supported by the Debian by design. It should be done only as a part of emergency recovery process. Despite of this situation, it is known to work well in many incidents. For critical systems, you should backup all important data on the system after the recovery operation and re-install the new system from the scratch.

你可以通过控制候选版本从新的档案库降级到旧的档案库(参见 第 2.7.3 节 “Tweaking candidate version”),从而使损坏的系统恢复。下面是一种懒惰的方法,可以避免许多冗长的 “dpkg -i <broken-package>_<old-version>.deb” 命令(参见 第 2.6.4 节 “使用 dpkg 命令进行救援”)。

搜索 “/etc/apt/sources.list” 文件中像下面那样使用 unstable 的行。

deb http://deb.debian.org/debian/ sid main contrib non-free

使用下面的行替换它,从而改为使用 testing

deb http://deb.debian.org/debian/ stretch main contrib non-free

像下面那样设置 “/etc/apt/preferences” 文件。

Package: *
Pin: release a=testing
Pin-Priority: 1010

运行 “apt-get update; apt-get dist-upgrade” 使整个系统的软件包强制降级。

在紧急降级后,移除 “/etc/apt/preferences” 这个特殊的文件。

[提示] 提示

这是一个好方法,移除(不是清除!)尽可能多地软件包,来减少依赖问题。你可能需要手动移除和安装一些软件包来使系统降级。需要特别注意 Linux 内核、引导程序、udev、PAM、APT 和网络相关的软件包以及它们的配置文件。

下面是一个建立小型公共软件包档案库的例子,兼容了现代的 secure APT 系统(参见 第 2.5.2 节 “Top level "Release" file and authenticity”)。让我们进行一些假定。

  • 账号名:“foo

  • 主机名:“www.example.com

  • 所需软件包:apt-utilsgnupg 和其它软件包

  • URL: "http://www.example.com/~foo/" ( → "/home/foo/public_html/index.html")

  • 软件包架构:“amd64

Create an APT archive key of Foo on your server system as the following.

$ ssh foo@www.example.com
$ gpg --gen-key
...
$ gpg -K
...
sec   1024D/3A3CB5A6 2008-08-14
uid                  Foo (ARCHIVE KEY) <foo@www.example.com>
ssb   2048g/6856F4A7 2008-08-14
$ gpg --export -a 3A3CB5A6 >foo.public.key

Publish the archive key file "foo.public.key" with the key ID "3A3CB5A6" for Foo

Create an archive tree called "Origin: Foo" as the following.

$ umask 022
$ mkdir -p ~/public_html/debian/pool/main
$ mkdir -p ~/public_html/debian/dists/unstable/main/binary-amd64
$ mkdir -p ~/public_html/debian/dists/unstable/main/source
$ cd ~/public_html/debian
$ cat > dists/unstable/main/binary-amd64/Release << EOF
Archive: unstable
Version: 4.0
Component: main
Origin: Foo
Label: Foo
Architecture: amd64
EOF
$ cat > dists/unstable/main/source/Release << EOF
Archive: unstable
Version: 4.0
Component: main
Origin: Foo
Label: Foo
Architecture: source
EOF
$ cat >aptftp.conf <<EOF
APT::FTPArchive::Release {
  Origin "Foo";
  Label "Foo";
  Suite "unstable";
  Codename "sid";
  Architectures "amd64";
  Components "main";
  Description "Public archive for Foo";
};
EOF
$ cat >aptgenerate.conf <<EOF
Dir::ArchiveDir ".";
Dir::CacheDir ".";
TreeDefault::Directory "pool/";
TreeDefault::SrcDirectory "pool/";
Default::Packages::Extensions ".deb";
Default::Packages::Compress ". gzip bzip2";
Default::Sources::Compress "gzip bzip2";
Default::Contents::Compress "gzip bzip2";

BinDirectory "dists/unstable/main/binary-amd64" {
  Packages "dists/unstable/main/binary-amd64/Packages";
  Contents "dists/unstable/Contents-amd64";
  SrcPackages "dists/unstable/main/source/Sources";
};

Tree "dists/unstable" {
  Sections "main";
  Architectures "amd64 source";
};
EOF

通过 dupload,你可以自动重复更新你服务器系统上的 APT 档案库内容。

当 “~/.dupload.conf” 包含如下内容时,在客户端执行 “dupload -t foo changes_file” 将所有的软件包文件放入 “~foo/public_html/debian/pool/main/”。

$cfg{'foo'} = {
  fqdn => "www.example.com",
  method => "scpb",
  incoming => "/home/foo/public_html/debian/pool/main",
  # The dinstall on ftp-master sends emails itself
  dinstall_runs => 1,
};

$cfg{'foo'}{postupload}{'changes'} = "
  echo 'cd public_html/debian ;
  apt-ftparchive generate -c=aptftp.conf aptgenerate.conf;
  apt-ftparchive release -c=aptftp.conf dists/unstable >dists/unstable/Release ;
  rm -f dists/unstable/Release.gpg ;
  gpg -u 3A3CB5A6 -bao dists/unstable/Release.gpg dists/unstable/Release'|
  ssh foo@www.example.com  2>/dev/null ;
  echo 'Package archive created!'";

The postupload hook script initiated by dupload(1) creates updated archive files for each upload.

你可以通过下面的方法将这个小型公共档案库添加到你客户端系统的 apt 源中。

$ sudo bash
# echo "deb http://www.example.com/~foo/debian/ unstable main" \
   >> /etc/apt/sources.list
# apt-key add foo.public.key
[提示] 提示

如果档案库位于本地文件系统中,你可以使用 “deb file:///home/foo/debian/ …”。

在任何的 Unix-like 环境中都可以不使用 dpkg(1),而使用标准的 ar(1)tar(1) 来解压 “dpkg*.deb” 软件包。

# ar x /path/to/dpkg_<version>_<arch>.deb
# ls
total 24
-rw-r--r-- 1 bozo bozo  1320 2007-05-07 00:11 control.tar.gz
-rw-r--r-- 1 bozo bozo 12837 2007-05-07 00:11 data.tar.gz
-rw-r--r-- 1 bozo bozo     4 2007-05-07 00:11 debian-binary
# mkdir control
# mkdir data
# tar xvzf control.tar.gz -C control
# tar xvzf data.tar.gz -C data

其它的 “*.deb” 软件包可以使用 dpkg-deb(1) 解压来获得上面的 “dpkg*.deb” 软件包;或像上面那样使用标准的 ar(1) 和较新的带有 xz(1) 解压支持的 GNU tar(1)

你也可以使用 mc 命令来浏览软件包内容。