「APT」- Advanced Package Tool

认识

官网:https://wiki.debian.org/Apt

Advanced package tool, or APT, is a free-software user interface that works with core libraries to handle the installation and removal of software on Debian and Debian-based Linux distributions. APT simplifies the process of managing software on Unix-like computer systems by automating the retrieval, configuration and installation of software packages, either from precompiled files or by compiling source code. 简而言之,APT 是个包管理工具,用来解决 Linux 发行版中软件包管理的问题。

Debian 是种主流的 Linux 操作系统,APT(高级软件包工具)是 Debian 系统上的软件包管理系统,它用于搜索、安装、更新和删除软件包。

组成

以下是与 Debian APT 和 DEB 相关的概念术语,这些概念术语是 Debian APT 的基础知识,可以帮助我们更好地理解和使用 APT 的使用。

软件源(Software Repository):软件源是一个在线服务器,存储了一系列软件包及其相关信息。APT 使用软件源来获取软件包,并通过更新软件源来获取最新的软件包版本;

软件包(Package):软件包是一个用于安装、更新或删除软件的文件。它包含了软件的二进制文件、配置文件、文档和其他相关的元数据;

依赖关系(Dependency):软件包可能依赖于其他软件包或特定版本的软件包。依赖关系描述了软件包之间的依赖关系,APT 会自动解决这些依赖关系,并确保所需的软件包都被正确安装;

源列表 sources.list

源列表是 APT 的配置文件,它包含了用于获取软件包的软件源的地址。通过编辑源列表,可以添加、删除或更改软件源;

dpkg

APT 使用软件包存储库来获取软件包,并自动解决依赖关系,使得软件包的安装和更新变得更加简单和可靠;

APT can be considered a front end to dpkg, friendlier than the older dselect front end. While dpkg performs actions on individual packages, APT manages relations (especially dependencies) between them, as well as sourcing and management of higher-level versioning decisions (release tracking and version pinning).

命令程序 and 配置文件

apt 高级的命令行界面的软件包管理系统。用于管理系统的软件包。
apt-cache
apt-cdrom
apt-config
apt-get
apt-key
apt-mark

/etc/apt/apt.conf.d/01-vendor-ubuntu
/etc/apt/apt.conf.d/01autoremove
/etc/cron.daily/apt-compat
/etc/kernel/postinst.d/apt-auto-removal
/etc/logrotate.d/apt

性质

它的主要目的是简化软件包的管理,使用户能够轻松地安装和更新软件包,同时保持操作系统的稳定性和安全性;

5)更新(Update):更新是指从软件源获取最新的软件包列表及其版本信息。更新软件源可以用来查找最新的软件包版本;

6)安装(Install):安装是将软件包从软件源下载并配置到系统中的过程。安装软件包可以通过 APT 命令来完成;

7)升级(Upgrade):升级是指将已安装的软件包更新到最新版本的过程。可以使用 APT 命令进行系统级别的升级,也可以使用 APT 命令升级单个软件包;

8)删除(Remove):删除是指将已安装的软件包从系统中彻底删除的过程。可以使用 APT 命令来删除软件包;

9)源码(Source):源码是软件包的原始代码,用于构建软件包的二进制文件。可以使用 APT 命令来获取软件包的源码;

构建

DeepSeek —— apt install 显示更多调试信息
sudo apt -o Debug::Acquire::http=true install <包名>
apt -o Debug::Acquire::http=true install <包名> 2>&1
apt-get -o Debug::Acquire::http=true install <包名>
env APT_CONFIG=”-o Debug::Acquire::http=true -o Debug::Acquire::https=true” apt install <包名>
apt -vvv -o Debug::Acquire::http=true -o Debug::Acquire::https=true install <包名>
apt -o Debug::pkgAcquire=1 install <包名>
sudo apt -o Debug::Acquire::http=true -o Debug::Acquire::https=true install <包名>

应用

用于在 Debian 和其衍生版本的 Linux 操作系统中安装、升级和卸载软件包;

场景 | 软件安装

apt-get install xxxxx

场景 | 仅下载软件包

How to download package not install it with apt-get command? – Unix & Linux Stack Exchange

apt-get install --download-only xxxxx

查看软件包下载地址 | Get installed packages url using apt

当从仓库中下载特别慢时,我们可以自己下载 deb 包,然后放入 /var/cache/apt/archives/ 中:

apt-get download --print-uris "<package-name>" # 打印下载链接
axel -n 5 "http://<package-url>" # 加速下载工具
mv "<package-name>" /var/cache/apt/archives/ # 移动到本地的缓存库

场景 | 非交互式安装 Non-Interactive Installation

bash – apt-get install tzdata noninteractive – Stack Overflow

命令行、使用 Docker 构建

在进行 APT 安装(或升级)时,某些软件的安装需要与用户进行交互,以选择合适的选项。但是,某些情况下,我们无法(或无需)进行交互,比如,Docker 镜像构建。该笔记将记录:在执行 APT 命令时,如何禁止交互,而采用默认选项。

我们以安装 tzdata 包为例,使用如下命令可以禁止交互:

DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends tzdata

参考