Linux中的dpkg命令 – 初学者参考

让我们在本文中讨论Linux中的dpkg命令。软件包有助于在Linux系统上交付或安装任何应用程序。实质上,软件包是安装程序或服务所需的文件和依赖项的压缩存档。

当您想在系统上安装新的程序或服务时,使用这些软件包。系统上的所有软件包都存储在本地的“仓库”中。

每当需要时,这个仓库可以被软件包管理服务访问。让我们今天谈谈其中一个软件包管理工具,Linux中的dpkg命令。

dpkg命令是什么?

基本上,man页面这样描述它:“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。

安装一个包

在Ubuntu中使用dpkg命令的最基本用途是安装软件包。我们可以使用dpkg -i命令选项在Ubuntu或Debian中安装deb软件包。

以下是安装软件包的步骤。

sudo dpkg -i [package name]

我们正在我们的Ubuntu系统上安装VLC播放器。请看下方屏幕截图,了解安装过程的外观。

Dpkg Command

你也可以通过在空格处分隔包名来同时安装多个包。

2. 卸载一个软件包

当你的系统不再需要一个程序或服务时,没有必要保留它。

在这里,dpkg命令也能帮助我们。

我们可以使用 dpkg -r 选项来从我们的系统中卸载程序或服务。

让我们删除这个演示安装的VLC播放器。

sudo dpkg -r [package name]

请查看下面的屏幕截图,看一下dpkg如何触发对所有依赖的菜单、桌面图标等进行更改,类似于apt命令。

Dpkg R Vlc

3. 更新你的代码库 nǐ de kù)

dpkg软件库存储了可供安装在你的Ubuntu或Debian Linux发行版上的所有软件包。

然而,由于这些包都是在本地存储的,所以当较新的版本已经发布时,你常常会遇到程序的旧版本包。这就需要一种更新存储库的方法。

猜猜看?dpkg –update-avail选项可以满足你的需求。

它会检查在线的软件仓库并将所有更新的软件包下载到本地仓库中。

让我们将本地仓库更新到最新版本:

sudo dpkg --update-avail

结尾备注

这就是今天我们要讨论的全部内容。对于大部分在Linux中使用dpkg命令的用户来说,这些就是你所需要的。大多数普通用户不需要更多的选项来执行该命令。然而,如果你是一个高级用户,你可以运行man dpkg来获取该命令的完整详细信息。

发表回复 0

Your email address will not be published. Required fields are marked *