初学者的Linux dpkg命令教程(8个示例)
如果您使用的是Debian或Debian系统(如Ubuntu),那么很可能遇到.deb软件包。 这些是Debian软件包,Linux命令行提供了内置命令/工具来处理这种软件包。 一个这样的工具是dpkg ,我们将在这里讨论这个教程。
但在这之前,值得一提的是本教程中的所有示例都已在Ubuntu 16.04LTS机器上进行了测试。
Linux dpkg命令
dpkg工具基本上是Debian / Debian系统的软件包管理器。 以下是它的语法:
dpkg ACTIONS
要么
dpkg [options] filename
以下是手册页的解释:
dpkg is a tool to install, build, remove and manage Debian packages.
The primary and more user-friendly front-end for dpkg is aptitude(1).
dpkg itself is controlled entirely via command line parameters, which
consist of exactly one action and zero or more options. The action-
parameter tells dpkg what to do and options control the behavior of the
action in some way.
dpkg can also be used as a front-end to dpkg-deb(1) and dpkg-query(1).
The list of supported actions can be found later on in the ACTIONS sec?
tion. If any such action is encountered dpkg just runs dpkg-deb or
dpkg-query with the parameters given to it, but no specific options are
currently passed to them, to use any such option the back-ends need to
be called directly.
以下是一些问答样式的例子,应该给你一个关于dpkg如何工作的基本概念。
Q1。 如何使用dpkg安装软件包?
这可以使用-i命令行选项来完成。
dpkg -i [package-name]
例如:
dpkg -i google-chrome-stable_current_amd64.deb
以下是安装过程中涉及的所有步骤:
1. Extract the control files of the new package.
2. If another version of the same package was installed before
the new installation, execute prerm script of the old package.
3. Run preinst script, if provided by the package.
4. Unpack the new files, and at the same time back up the old
files, so that if something goes wrong, they can be restored.
5. If another version of the same package was installed before
the new installation, execute the postrm script of the old pack?
age. Note that this script is executed after the preinst script
of the new package, because new files are written at the same
time old files are removed.
6. Configure the package. See --configure for detailed informa?
tion about how this is done.
Q2。 如何使用dpkg删除已安装的软件包?
这可以使用-r命令行选项完成。
dpkg -r [package-name]
例如:
dpkg -r googler_3.3.0-1_all.deb
以下是手册页中关于此选项的说明:
Removing of a package consists of the following steps:
1. Run prerm script
2. Remove the installed files
3. Run postrm script
Q3。 如何列出系统中所有已安装的软件包?
为此,您可以使用-l命令行选项。
dpkg -l
例如,下面是我的系统上生成的这个命令行选项的输出:
Q4。 如何制作包的dpkg列表内容?
这可以使用--contents标志完成。
dpkg --contents [package name]
例如:
Q5。 如何使用dpkg解压缩包?
有时您可能只想解压缩包,而不是配置它。 那么,dpkg也提供了这个选项:--unpack。
dpkg --unpack [package-name]
如果稍后想要配置一个已经解包的软件包,可以使用--configure命令行选项。
dpkg --configure [package-name]
以下是手册页中关于此选项的说明:
Configuring consists of the following steps:
1. Unpack the conffiles, and at the same time back up the old
conffiles, so that they can be restored if something goes wrong.
2. Run postinst script, if provided by the package.
Q6。 如何检查包是否安装?
为此使用-s命令行选项。
dpkg -s [package-name]
例如:
Q7。 如何打印软件包的结构dpkg installs?
可以使用--print-architecture命令行选项访问此信息。
dpkg --print-architecture
例如,在我的系统上生成的上述命令的输出是:
amd64
Q8。 如何使用dpkg清除软件包?
我们已经讨论了如何使用dpkg命令删除软件包。 你也可以清除一个软件包,一个删除所有内容的进程,包括conffiles。 这可以使用-P命令行选项完成。
dpkg -P [package-name]
以下是手册页关于此选项的说明:
Some configuration files might be unknown to dpkg because
they are created and handled separately through the configura?
tion scripts. In that case, dpkg won't remove them by itself,
but the package's postrm script (which is called by dpkg), has
to take care of their removal during purge. Of course, this only
applies to files in system directories, not configuration files
written to individual users' home directories.
Purging of a package consists of the following steps:
1. Remove the package, if not already removed. See --remove for
detailed information about how this is done.
2. Run postrm script.
结论
dpkg命令提供了许多选项。 我们在这里讨论的是那些可以帮助您开始使用该工具的选项。 完成这些练习之后,请前往命令的手册页以获取更多信息。