Linux中安装的软件包
Contents
1. 概述
基于 Linux 的系统使用客户端应用程序来帮助进行包管理。虽然默认预装了一些软件包,但 Linux 用户可以在需要时安装其他软件包。
在本教程中,我们将看到列出 Linux 中所有已安装软件包的五种方法——使用*apt *、dpkg 、snap 、dnf 和flatpak 。
2. 使用apt包管理器
apt 是一个命令行工具,可与基于 Debian 的系统(例如 Ubuntu)中的高级打包工具 (APT) 一起使用。用于安装新软件包、升级现有软件包、更新软件包列表索引、升级整个 Ubuntu 系统。
2.1. 列出已安装的软件包
我们使用 ––installed 标签仅列出已安装的软件包。
$ apt list --installed | head
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Listing...
accountsservice/now 0.6.55-0ubuntu12~20.04.4 amd64 [installed,upgradable to: 0.6.55-0ubuntu12~20.04.5]
acl/focal,now 2.2.53-6 amd64 [installed,automatic]
acpi-support/focal,now 0.143 amd64 [installed,automatic]
acpid/focal,now 1:2.0.32-1ubuntu1 amd64 [installed,automatic]
adduser/focal,focal,now 3.118ubuntu2 all [installed,automatic]
adwaita-icon-theme/focal-updates,focal-updates,now 3.36.1-2ubuntu0.20.04.2 all [installed,automatic]
aisleriot/focal,now 1:3.22.9-1 amd64 [installed,automatic]
alsa-base/focal,focal,now 1.0.25+dfsg-0ubuntu5 all [installed,automatic]
alsa-topology-conf/focal,focal,now 1.2.2-1 all [installed,automatic]
...
已安装的软件包具有这三个标签中的任何一个;[installed],[installed,automatic]和[installed,local]
- [installed] – 显示软件包是从存储库列表中手动安装的
- [installed,automatic] – 表示软件包是作为另一个软件包的依赖项自动安装的
- [installed,local] – 显示软件包不在官方仓库列表中
2.2. 列出软件包
我们使用apt list命令列出所有已安装和可用的软件包。
$ apt list | head
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Listing...
0ad-data-common/focal,focal 0.0.23.1-1 all
0ad-data/focal,focal 0.0.23.1-1 all
0ad/focal 0.0.23.1-4ubuntu3 amd64
0install-core/focal 2.15.1-1 amd64
0install/focal 2.15.1-1 amd64
0xffff/focal 0.8-1 amd64
2048-qt/focal 0.1.6-2build1 amd64
2ping/focal,focal 4.3-1 all
2to3/focal,focal 3.8.2-0ubuntu2 all
apt list命令的输出很长。我们通过管道将它传递给head 命令以仅列出前十行。
2.3. 列出特定包
我们将包名称添加到apt list命令以列出特定包。
$ apt list python3 --installed
Listing... Done
python3/focal,now 3.8.2-0ubuntu2 amd64 [installed,automatic]
```
我们列出了包python3的详细信息。
## 3. 使用*dpkg*包管理器
*dpkg*是基于 Debian 系统的包管理器。
**列出我们系统上已安装的软件包:**
```bash
$ dpkg --get-selections | grep -w "install" | head
accountsservice install
acl install
acpi-support install
acpid install
adduser install
adwaita-icon-theme install
aisleriot install
alsa-base install
alsa-topology-conf install
alsa-ucm-conf install
```
*––get-selections*获取包选择列表并将输出写入 stdout。我们可以将此输出传输到*[grep](https://man7.org/linux/man-pages/man1/grep.1.html)*命令,该命令选择与单词“install”匹配的行。通过head命令显示输出的前 1o 行。
另一种方法是使用 *[dpkg-query](https://man7.org/linux/man-pages/man1/dpkg-query.1.html)*工具。该工具查询dpkg数据库。
```bash
$ dpkg-query -l | head
ii accountsservice 0.6.55-0ubuntu12~20.04.4 amd64 query and manipulate user account information
ii acl 2.2.53-6 amd64 access control list - utilities
ii acpi-support 0.143 amd64 scripts for handling many ACPI events
ii acpid 1:2.0.32-1ubuntu1 amd64 Advanced Configuration and Power Interface event daemon
ii adduser 3.118ubuntu2 all add and remove users and groups
ii adwaita-icon-theme 3.36.1-2ubuntu0.20.04.2 all default icon theme of GNOME (small subset)
ii aisleriot 1:3.22.9-1 amd64 GNOME solitaire card game collection
ii alsa-base 1.0.25+dfsg-0ubuntu5 all ALSA driver configuration files
ii alsa-topology-conf 1.2.2-1 all ALSA topology configuration files
ii alsa-ucm-conf 1.2.2-1ubuntu0.5 all ALSA Use Case Manager configuration files
```
*-l*选项列出了我们系统上安装的所有软件包。
## 4. 使用*snap*包管理器
*snap*是 Canonical 开发的 Linux 中的替代包管理器。
** *snap list*命令列出所有使用 snap 安装的软件包。**
```bash
$ snap list
Name Version Rev Tracking Publisher Notes
core 16-2.54.4 12834 latest/stable canonical* core
hello-world 6.4 29 latest/stable canonical* -
```
## 5. 使用*dnf*包管理器
*dnf*旨在替代 基于 Red Hat 的系统上的[yum](https://man7.org/linux/man-pages/man8/yum.8.html) 包管理器。
**使用*dnf*列出我们系统上已安装的软件包:**
```bash
$ dnf list installed
Installed Packages
acl.x86_64 2.2.53-1.el8 @anaconda
audit.x86_64 3.0-0.10.20180831git0047a6c.el8 @anaconda
audit-libs.x86_64 3.0-0.10.20180831git0047a6c.el8 @anaconda
```
## 6. 使用*Flatpak*
*flatpak*是一个包管理软件,用于跨各种 Linux 发行版分发软件。
**要查看我们系统上所有已安装的*flatpak*应用程序:**
```bash
$ flatpak list --app
Name Application ID Version Branch Installation
Fondo com.github.calo001.fondo 1.3.8 stable system
Flatseal com.github.tchx84.Flatseal 1.5.2 stable system
GNOME Boxes org.gnome.Boxes 3.36.6 stable system
```