# APT（软件包管理器）

**APT**（高级软件包工具，也写作高级打包工具）是 Debian 及其衍生发行版（如 Ubuntu）的主要命令行软件包管理器。它从经过认证的软件源获取软件包及其相关信息，解析依赖关系，并安装、升级和卸载软件包以及它们所依赖的库和工具。<sup>[1](https://github.com/Debian/apt/blob/main/README.md)</sup> 该项目提供命令行工具 `apt-get` 和 `apt-cache`，以及对 `libapt-pkg` 库所有功能的底层访问，更高级的软件包管理器可以依赖该库。<sup>[1](https://github.com/Debian/apt/blob/main/README.md)</sup><sup> • </sup><sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup>

| 关键事实 | 详情 |
|---|---|
| 全称 | 高级软件包工具；Debian 打包系统的前端，构建于 `libapt-pkg` 库之上<sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup> |
| 核心工具 | `apt-get` 用于获取、安装、升级和卸载；`apt-cache` 用于查询软件包信息<sup>[1](https://github.com/Debian/apt/blob/main/README.md)</sup> |
| `apt` 二进制 | 自 Debian Jessie 起，常用的 `apt-get` 和 `apt-cache` 命令在单一的 `apt` 命令中有了对应形式，如 `apt update`、`apt install` 和 `apt full-upgrade`<sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup> |
| 软件源配置 | 软件包来源列于 `/etc/apt/sources.list` 及 `/etc/apt/sources.list.d/` 下的文件中，采用单行 `.list` 或 deb822 `.sources` 格式<sup>[3](https://manpages.debian.org/testing/apt/sources.list.5.en.html)</sup> |
| 认证 | 对软件源 Release 文件的签名校验于 2003 年在 apt 0.6 中实现，Debian 于 2005 年迁移至该机制<sup>[4](https://wiki.debian.org/SecureApt)</sup> |
| 当前版本 | APT 3.0 随 Ubuntu 25.04 发布；apt 3.0.0 于 2025 年 4 月 10 日迁移至 Debian testing<sup>[5](https://documentation.ubuntu.com/release-notes/25.04/)</sup><sup> • </sup><sup>[6](https://tracker.debian.org/news/1637565/apt-300-migrated-to-testing/)</sup> |
| 可移植性 | 通过移植，该工具可与其它软件包管理系统配合使用，如 Red Hat 软件包管理器（rpm）<sup>[7](https://www.debian.org/doc/manuals/debian-faq/debian-faq.en.pdf)</sup> |

## 工作原理

APT 将软件包作为一个整体来处理，而非逐一评估：它综合考虑可用且兼容的软件包，并根据依赖关系产生尽可能最佳的组合。<sup>[8](https://www.debian.org/doc/manuals/debian-handbook/apt.en.html)</sup> 与底层的 `dpkg` 工具不同，`apt-get` 不直接理解 `.deb` 文件；它依据软件包的正确名称工作，只能从 `/etc/apt/sources.list` 中配置的源安装 `.deb` 归档，并在下载归档后调用 `dpkg`。<sup>[9](https://www.debian.org/doc/manuals/apt-guide/ch2.en.html)</sup><sup> • </sup><sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup>

在安装任何东西之前，必须先用 `apt-get update`（或 `apt update`）从配置的源获取软件包列表，这会填充 APT 的可用软件包数据库。<sup>[9](https://www.debian.org/doc/manuals/apt-guide/ch2.en.html)</sup><sup> • </sup><sup>[8](https://www.debian.org/doc/manuals/debian-handbook/apt.en.html)</sup> 随后 `upgrade` 命令以温和的方式升级已安装的软件包：它从不安装新软件包或移除现有软件包，如果升级某个软件包会破坏另一个软件包，它就不会执行该升级。`full-upgrade` 命令（历史上称为 `dist-upgrade`）则不那么保守，在完成升级需要时可以安装或移除软件包。<sup>[9](https://www.debian.org/doc/manuals/apt-guide/ch2.en.html)</sup><sup> • </sup><sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup>

APT 还会跟踪哪些软件包是作为依赖自动安装的。当依赖它们的应用程序被移除后，`apt-get autoremove` 或 `apt autoremove` 可以删除不再需要的软件包。<sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup>

## 软件源配置

`/etc/apt/sources.list` 中每个生效的行代表一个软件包来源（一个仓库，不要与源码包混淆），由至少三个以空格分隔的部分组成：类型、基础 URL 和发行版，后面可选地跟有组件。<sup>[8](https://www.debian.org/doc/manuals/debian-handbook/apt.en.html)</sup> `deb` 类型指定二进制软件包仓库，`deb-src` 指定源码包仓库；URL 可以使用 `file://` 表示本地源，`http://` 或 `https://` 表示 Web 服务器，`ftp://` 或 `ftps://` 表示 FTP 服务器。<sup>[8](https://www.debian.org/doc/manuals/debian-handbook/apt.en.html)</sup>

支持两种文件格式。传统的单行风格使用 `.list` 扩展名，所有 apt 版本均支持，但已被弃用，且可能在 2029 年之前不会被移除。deb822 风格使用 `.sources` 扩展名，自 apt 1.1 版起得到支持，旨在成为默认格式，因为它更易于创建、扩展和修改。<sup>[3](https://manpages.debian.org/testing/apt/sources.list.5.en.html)</sup> 较新的 Ubuntu 发行版默认使用 deb822 格式，仓库信息位于 `/etc/apt/sources.list.d/ubuntu.sources`；24.04 LTS（Noble）之前的发行版在 `/etc/apt/sources.list` 中定义仓库。<sup>[10](https://ubuntu.com/server/docs/how-to/software/package-management/)</sup>

## 固定与版本选择

当启用多个仓库时，APT 会为软件包分配整数优先级；数值越高表示越优先。如果某个软件包的两个版本具有不同的优先级，优先级高的胜出；优先级相同时，版本号高的胜出。默认优先级为 500。<sup>[11](https://wiki.debian.org/AptConfiguration)</sup> 通过分配优先级来控制软件包来自哪个仓库，称为 apt-pinning，通过 `/etc/apt/preferences` 和 `apt_preferences(5)` 规则进行配置。<sup>[12](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)</sup>

固定有实际用途：Debian backports 仓库的默认优先级为 100，而 stable 为 500，因此 backports 的软件包仅在明确请求时才会安装；固定还可以将第三方仓库限制为少数几个软件包，而忽略其余部分。<sup>[11](https://wiki.debian.org/AptConfiguration)</sup> 没有 preferences 文件时，APT 使用版本字符串选择最新的可用版本作为候选版本，这是正常且推荐的用法；官方支持的归档组合不需要固定，因为不应作为自动升级来源的归档被标记为 NotAutomatic。<sup>[12](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)</sup> 不支持混用归档，例如 Debian 和 Ubuntu 仓库，需要管理员自行确保兼容性，因为 Debian 不对此作出保证。<sup>[12](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)</sup>

## 安全性

APT 通过一系列加密哈希和签名来验证仓库元数据的真实性，详见 `apt-secure(8)`。自 Debian 10 Buster 起，被签名的文件是镜像提供的 `InRelease` 文件，同时还有旧式的 `Release` 文件；两者都列出了 `Packages` 索引文件及其 SHA256 哈希值，因此对索引或其描述的软件包的篡改是可检测的。<sup>[13](https://www.debian.org/doc/manuals/debian-handbook/sect.package-authentication.en.html)</sup> 签名校验于 2003 年在 apt 0.6 版中实现，Debian 于 2005 年迁移至该机制。<sup>[4](https://wiki.debian.org/SecureApt)</sup> 自 apt 1.1 起，仓库必须提供较新的认证信息才能不受阻碍地使用；自 1.5 起，对仓库 Release 文件中信息的更改必须经过确认，APT 才会继续应用来自该仓库的更新。<sup>[14](https://manpages.debian.org/testing/apt/apt-secure.8.en.html)</sup>

第三方仓库需要受信任的 GPG 密钥。推荐的做法是在源条目中使用 `Signed-By` 选项将密钥绑定到特定仓库，而不是将密钥添加到共享的受信任密钥环中——在后者中，任何匹配的密钥都会认证任何归档。<sup>[13](https://www.debian.org/doc/manuals/debian-handbook/sect.package-authentication.en.html)</sup> `apt-key` 命令自 Debian 13 “Trixie” 起已被移除；[签名](https://www.edgepedia.org/zh/signature)验证现在直接使用 `gpgv`。<sup>[4](https://wiki.debian.org/SecureApt)</sup><sup> • </sup><sup>[5](https://documentation.ubuntu.com/release-notes/25.04/)</sup>

## 前端与 apt 命令

Debian 常见问题解答将 APT 描述为 Debian 打包系统的高级接口，提供 `apt-get`，以及用于搜索、管理和查询软件包的命令行工具。<sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup> 自 Debian Jessie 起，`apt` 二进制将最常用的 `apt-get` 和 `apt-cache` 命令合并在一起，并提供了面向人类的更花哨的彩色输出格式；对于脚本和高级用例，`apt-get` 仍然是更可取的选择。<sup>[2](https://www.debian.org/doc/manuals/debian-faq/pkgtools)</sup> Debian 参考手册建议交互式命令行工作使用 `apt`，脚本使用 `apt-get`，交互式全屏文本界面使用 `aptitude`。<sup>[12](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)</sup>

`apt-get` 被描述为适合发行版之间的大版本系统升级，具有健壮的依赖解析器，且硬件需求低于 aptitude——后者消耗更多内存、运行更慢，但提供对所有软件包元数据的增强正则搜索，并且无需 preferences 文件即可管理多个软件包版本。<sup>[12](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)</sup> Synaptic 等图形前端也构建在相同的 APT 基础设施之上。<sup>[12](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)</sup>

## 历史与近期版本

Debian 2.1 包含了 apt，项目历史将其描述为下一代 Debian 软件包管理器接口。<sup>[15](https://www.debian.org/doc/manuals/project-history/detailed.en.html)</sup> Debian 手册指出，`apt-get` 历史上仅被设计为 `libapt-pkg` 的测试前端，而它的成功往往掩盖了这一事实。<sup>[16](https://debian-handbook.info/download/squeeze/debian-handbook.pdf)</sup>

3.0 系列是当前的主要代际。Ubuntu 25.04 随附 APT 3.0，其中当经典求解器无法找到解决方案时会自动使用新的依赖求解器，TLS 连接和文件哈希从 GnuTLS 和 gcrypt 迁移至 OpenSSL，并为 `apt(8)` 的 `show` 和 `list` 等命令添加了自动分页器。<sup>[5](https://documentation.ubuntu.com/release-notes/25.04/)</sup> 在 Debian 中，apt 3.0.0 于 2025 年 4 月 10 日迁移至 testing，取代了 2.9.35 版。<sup>[6](https://tracker.debian.org/news/1637565/apt-300-migrated-to-testing/)</sup>

## References

1. [apt README, Debian apt team (GitHub)](https://github.com/Debian/apt/blob/main/README.md)
2. [Chapter 8, The Debian package management tools, Debian FAQ](https://www.debian.org/doc/manuals/debian-faq/pkgtools)
3. [sources.list(5), Debian Manpages (apt, testing)](https://manpages.debian.org/testing/apt/sources.list.5.en.html)
4. [SecureApt, Debian Wiki](https://wiki.debian.org/SecureApt)
5. [Ubuntu 25.04 release notes, Package Management: APT 3.0](https://documentation.ubuntu.com/release-notes/25.04/)
6. [apt 3.0.0 MIGRATED to testing, Debian Package Tracker](https://tracker.debian.org/news/1637565/apt-300-migrated-to-testing/)
7. [The Debian GNU/Linux FAQ (PDF)](https://www.debian.org/doc/manuals/debian-faq/debian-faq.en.pdf)
8. [Chapter 6, Maintenance and Updates: The APT Tools, The Debian Administrator's Handbook](https://www.debian.org/doc/manuals/debian-handbook/apt.en.html)
9. [Chapter 2, apt-get, APT User's Guide](https://www.debian.org/doc/manuals/apt-guide/ch2.en.html)
10. [Install and manage packages, Ubuntu Server documentation](https://ubuntu.com/server/docs/how-to/software/package-management/)
11. [AptConfiguration, Debian Wiki](https://wiki.debian.org/AptConfiguration)
12. [Chapter 2, Debian package management, Debian Reference](https://www.debian.org/doc/manuals/debian-reference/ch02.en.html)
13. [Section 6.6, Checking Package Authenticity, The Debian Administrator's Handbook](https://www.debian.org/doc/manuals/debian-handbook/sect.package-authentication.en.html)
14. [apt-secure(8), Debian Manpages (apt, testing)](https://manpages.debian.org/testing/apt/apt-secure.8.en.html)
15. [A Detailed History of Debian, Debian Project](https://www.debian.org/doc/manuals/project-history/detailed.en.html)
16. [The Debian Administrator's Handbook (Squeeze edition, PDF), chapter on APT front ends](https://debian-handbook.info/download/squeeze/debian-handbook.pdf)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Build, deployment, and development tooling › Package managers

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/apt-package-manager

English original: https://www.edgepedia.org/apt-package-manager
