Linux 中的 dpkg 命令 - 初学者参考
让我们在本文中讨论 Linux 中的 dpkg 命令。软件包有助于在 Linux 系统上交付或安装任何应用程序。本质上,包是安装程序或服务所需的文件和依赖项的压缩存档。
当您想在他们的系统上安装新程序或服务时,将使用这些软件包。系统上的所有包都存储在本地“存储库”中。
需要时,包管理服务可以访问此存储库。让我们来谈谈其中一个包管理实用程序,即今天 Linux 中的 dpkg 命令。
什么是 dpkg 命令?
本质上,手册页是这样描述的:“dpkg 是一个用于安装、构建、删除和管理 Debian 软件包的工具。”
我们使用 dpkg 命令与我们系统上的包进行交互。它在命令行参数的帮助下得到完全控制,第一个参数称为操作参数,用于指示要做什么。此参数后面可以也可以不跟任何其他参数。
后来,一个名为 aptitude 的新工具旨在为用户提供一个更加用户友好的交互式前端来管理包,而无需使用 dpkg 命令的复杂性。它代表用户与 dpkg 接口交互。现在,让我们尝试了解 Linux 中的 dpkg 命令。
Linux 中 dpkg 命令的基础知识
dpkg 命令的基本语法如下所示:
dpkg [options] [.deb package name]
dpkg 命令提供了一长串选项来自定义我们在分析网络时接收到的数据。这是一些最流行的 dpkg 选项的列表。
Option | Function |
-i OR --install | Install a package using the dpkg command. The command will extract all control files for the specified package, remove any previously installed older instance of the package, and install the new package on our system. |
-r OR --remove | Remove an installed package from our system. It removes every file belonging to the specific package except the configuration files. This can be seen as the uninstallation option. |
-P OR --purge | An alternative way to remove an installed package from our system. It completely removes every fie belonging to the specific package, including the configuration files. This can be seen as the ‘complete uninstallation’ option. |
--update-avail | Uhe information of the dpkg command about available packages in its repositories. If new packages are available, they are synced from the official repositories. |
--merge-avail | Merge the information of the dpkg command about available packages in its repositories with previously available information. It is usually run right after the previous command. |
--help | Display the help page for the dpkg command and exit. |
这些是 dpkg 命令最常用的一些选项,您可以通过在终端中显示帮助选项来探索更多信息。
使用 dpkg 命令
让我们探讨 dpkg 命令的常见用法。由于该命令对 Debian 和 Ubuntu 系统的作用相同,因此从现在开始,我们将在本教程中仅提及 Ubuntu。
1.安装包
在 Ubuntu 中 dpkg 命令最基本的用法是安装包。我们可以使用 dpkg -i
命令选项在 Ubuntu 或 Debian 中安装 deb 包。
这是安装包的方法。
sudo dpkg -i [package name]
我们正在我们的 Ubuntu 系统上安装 VLC 播放器。查看下面的屏幕截图,了解安装在屏幕上的样子。
您还可以通过指定以空格分隔的包名称来同时安装多个包。
2.删除包
当您不再需要系统上的程序或服务时,保留它也没有用。
dpkg 命令也让我们了解了这里。
我们可以使用 dpkg -r
选项从系统中卸载程序或服务。
让我们删除为此演示安装的 VLC 播放器。
sudo dpkg -r [package name]
查看下面的屏幕截图,了解 dpkg 如何触发所有相关菜单、桌面图标等类似于 apt 命令的更改。
3.更新您的存储库
dpkg 存储库存储所有可用于在 Ubuntu 或 Debian Linux 发行版上安装的软件包。
然而,由于这些包存储在本地,当新版本已经发布时,您通常会得到旧版本的程序包。这导致需要一种方法来更新您的存储库。
你猜怎么了? dpkg --update-avail
选项可以满足您的要求。
它检查在线存储库并将所有更新的包下载到您的本地存储库。
让我们将本地存储库更新到最新版本:
sudo dpkg --update-avail
结语
这使我们结束了今天的主题。在 Linux 中使用 dpkg 命令时,大部分情况下,这就是您所需要的。大多数普通用户不需要超过这三个命令选项。但是,如果您是高级用户,则可以运行 man dpkg
并获取该命令可以执行的所有操作的完整详细信息。