Detailed explanation of dpkg command in Ubuntu system

dpkg, package manager for Debian, is a major package management tool in Debian and Debian based systems. It can be used to install, build, uninstall and manage deb format software packages.

Install software

When installing software with the dpkg command, you can use the - i option and specify the path of the deb installation package. It is different from apt get (Advanced Package Tool), another package management tool under Ubuntu.
The apt get command does not directly manipulate the deb installation package file, but from / etc / apt / sources Download and install the software package from the software image source defined in the list configuration file. When using, you only need to specify the name of the software (or you can attach the version number).

Apt get command to install software:
$ apt-get install <package_name[=version]>

dpkg command to install software:
$ dpkg -i <package_file_path>

Therefore, dpkg is mainly used to install deb packages that have been downloaded locally, or to manage the installed software. Apt get can download and install software directly from the remote software warehouse.

$ sudo apt-get install emacs
 Reading package list... complete
 Analyzing dependency tree for package
 Reading status information... complete
 The following software will also be installed:
  emacs-bin-common emacs-common emacs-el emacs-gtk libm17n-0
  libotf0 m17n-db
 Recommended installation:
  mailutils emacs-common-non-dfsg m17n-docs gawk
 The following [new] packages will be installed:
  emacs emacs-bin-common emacs-common emacs-el emacs-gtk libm17n-0
  libotf0 m17n-db
 0 packages have been upgraded and 8 packages have been newly installed. To uninstall 0 packages, 115 packages have not been upgraded.
Need to download 34.4 MB Archive of.
It will consume 137 after decompression MB Extra space.
Do you want to continue? [Y/n]
$ sudo dpkg -i fping_4.2-1_amd64.deb
(Reading database ... The system currently has 252654 files and directories installed.)
Ready to unzip fping_4.2-1_amd64.deb  ...
Decompressing fping (4.2-1) And cover (4.2-1) ...
Setting fping (4.2-1) ...
Processing for man-db (2.8.5-2) Trigger for ...

List installed software

You can use the dpkg -l command to list the installed software and the status of software packages in the current system. For example:

$ dpkg -l
 Expected state=unknown(u)/install(i)/delete(r)/eliminate(p)/keep(h)
| state=Not installed(n)/already installed(i)/Configuration only(c)/Extract only(U)/Configuration failed(F)/Incomplete installation(H)/Trigger wait(W)/Trigger pending(T)
|/ error?=(nothing)/Must be reinstalled(R) (Status, error: uppercase=fault)
||/ name                                          edition                                Architecture     describe
+++-=============================================-===================================-============-===============================================================================
ii  2048-qt                                       0.1.6-1build1                       amd64        mathematics based puzzle game
ii  accountsservice                               0.6.50-0ubuntu1                     amd64        query and manipulate user account information
ii  acl                                           2.2.53-4                            amd64        access control list - utilities
ii  acpi-support                                  0.143                               amd64        scripts for handling many ACPI events
ii  acpid                                         1:2.0.31-1ubuntu2                   amd64        Advanced Configuration and Power Interface event daemon
ii  adduser                                       3.118ubuntu1                        all          add and remove users and groups
ii  adwaita-icon-theme                            3.32.0-1ubuntu1                     all          default icon theme of GNOME (small subset)
ii  alsa-base                                     1.0.25+dfsg-0ubuntu5                all          ALSA driver configuration files
ii  alsa-utils                                    1.1.8-1ubuntu1                      amd64        Utilities for configuring and using ALSA
...

The first column ii in the output of each line of the command indicates the installation and configuration status of the software package, and its format is as follows:
Expected state | current state | error
The expected states are as follows:

  • u: That is, unknown, the package is not installed and the user has not requested installation
  • i: That is, install. The user requests to install the software package
  • r: That is, remove. The user requests to uninstall the package
  • p: That is, purge, the user requests to uninstall the package and clean up the configuration file
  • h: That is, hold, the user requests to keep the current software package version

The current status is as follows:

  • n: That is, not installed, the package is not installed
  • i: That is, installed, the software package has been installed and configured
  • c: That is, config files. The package has been uninstalled, but its configuration file has not been cleaned up
  • u: That is, unpacked. The package has been decompressed but not configured
  • f: That is, half configured. An error occurred while configuring the package
  • w: That is, triggers waited
  • t: That is, triggers pending

There are several error states:

  • h: The package is forced to remain
  • r: That is, reinstall required. You need to uninstall and reinstall
  • x: The package is corrupted

Therefore, ii indicates that the software needs to be installed and has been installed without errors;
iu indicates that the software has been installed but not configured correctly;
rc indicates that the software has been deleted, but the configuration file has not been cleaned up.

To view packages in rc state:

$ dpkg -l | grep ^rc
rc  libmhash2:amd64                               0.9.9.9-7                           amd64        Library for cryptographic hashing and message authentication
rc  linux-image-5.0.0-13-generic                  5.0.0-13.14                         amd64        Signed kernel image generic
rc  linux-modules-5.0.0-13-generic                5.0.0-13.14                         amd64        Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
rc  linux-modules-extra-5.0.0-13-generic          5.0.0-13.14                         amd64        Linux kernel extra modules for version 5.0.0 on 64 bit x86 SMP
rc  zabbix-proxy-mysql                            1:4.0.4+dfsg-1                      amd64        network monitoring solution - proxy (using MySQL)

In addition, you can use dpkg - L < package_ name_ The pattern > command filters out packages whose names contain the specified pattern.

$ dpkg -l "nginx*"
Expected state=unknown(u)/install(i)/delete(r)/eliminate(p)/keep(h)
| state=Not installed(n)/already installed(i)/Configuration only(c)/Extract only(U)/Configuration failed(F)/Incomplete installation(H)/Trigger wait(W)/Trigger pending(T)
|/ error?=(nothing)/Must be reinstalled(R) (Status, error: uppercase=fault)
||/ name           edition            Architecture     describe
+++-==============-===============-============-=========================================================
ii  nginx          1.15.9-0ubuntu1 all          small, powerful, scalable web/proxy server
ii  nginx-common   1.15.9-0ubuntu1 all          small, powerful, scalable web/proxy server - common files
ii  nginx-core     1.15.9-0ubuntu1 amd64        nginx web/proxy server (standard version)
un  nginx-doc      <nothing>            <nothing>         (No description)
un  nginx-extras   <nothing>            <nothing>         (No description)
un  nginx-full     <nothing>            <nothing>         (No description)
un  nginx-light    <nothing>            <nothing>         (No description)

Uninstall software

The - r option of the dpkg command can be used to uninstall the installed software package. At this time, you only need to specify the name of the software.

$ sudo dpkg -r vim
(Reading database ... The system currently has 252653 files and directories installed.)
Uninstalling vim (2:8.1.0320-1ubuntu3.1) ...
update-alternatives: use /usr/bin/vim.tiny To provide in automatic mode /usr/bin/vi (vi)
update-alternatives: use /usr/bin/vim.tiny To provide in automatic mode /usr/bin/view (view)
update-alternatives: use /usr/bin/vim.tiny To provide in automatic mode /usr/bin/ex (ex)
update-alternatives: use /usr/bin/vim.tiny To provide in automatic mode /usr/bin/rview (rview)

It should be noted that the - r option will only remove the specified package without affecting its configuration file. You can use the - P option to clean up the configuration file while deleting the package.
sudo dpkg -P <package>

Other package management operations

View the contents of the package

dpkg -c <package_file_path>

$ dpkg -c fping_4.2-1_amd64.deb
drwxr-xr-x root/root         0 2019-02-20 06:27 ./
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/bin/
-rwxr-xr-x root/root     52128 2019-02-20 06:27 ./usr/bin/fping
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/bug/
-rwxr-xr-x root/root       118 2017-06-19 05:19 ./usr/share/bug/fping
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/doc/
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/doc/fping/
-rw-r--r-- root/root       495 2017-09-06 08:00 ./usr/share/doc/fping/NEWS.Debian.gz
-rw-r--r-- root/root      1615 2019-02-20 06:27 ./usr/share/doc/fping/changelog.Debian.gz
-rw-r--r-- root/root      3445 2017-12-07 04:09 ./usr/share/doc/fping/copyright
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/lintian/
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/lintian/overrides/
-rw-r--r-- root/root        41 2017-06-19 05:19 ./usr/share/lintian/overrides/fping
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/man/
drwxr-xr-x root/root         0 2019-02-20 06:27 ./usr/share/man/man8/
-rw-r--r-- root/root      5733 2019-02-20 06:27 ./usr/share/man/man8/fping.8.gz
-rw-r--r-- root/root      1512 2019-02-20 06:27 ./usr/share/man/man8/fping6.8.gz
lrwxrwxrwx root/root         0 2019-02-20 06:27 ./usr/bin/fping6 -> fping
View the details of the package (installed)

Dpkg - s < package > or dpkg -- status < package >

$ dpkg -s fping
Package: fping
Status: deinstall ok installed
Priority: optional
Section: net
Installed-Size: 87
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Version: 4.2-1
Depends: libcap2-bin, netbase, libc6 (>= 2.15)
Enhances: netdata (>= 1.5)
Description: sends ICMP ECHO_REQUEST packets to network hosts
 fping is a ping like program which uses the Internet Control Message Protocol
 (ICMP) echo request to determine if a target host is responding.  fping
 differs from ping in that you can specify any number of targets on the command
 line, or specify a file containing the lists of targets to ping.  Instead of
 sending to one target until it times out or replies, fping will send out a
 ping packet and move on to the next target in a round-robin fashion.
Original-Maintainer: Axel Beckert <abe@debian.org>
Homepage: https://www.fping.org/
View the installation location of the package

Dpkg - L < package > or dpkg -- list files < package >

$ dpkg -L fping
/.
/usr
/usr/bin
/usr/bin/fping
/usr/share
/usr/share/bug
/usr/share/bug/fping
/usr/share/doc
/usr/share/doc/fping
/usr/share/doc/fping/NEWS.Debian.gz
/usr/share/doc/fping/changelog.Debian.gz
/usr/share/doc/fping/copyright
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/fping
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/fping.8.gz
/usr/share/man/man8/fping6.8.gz
/usr/bin/fping6
Filter out the package containing the specified file (mode)

dpkg -S <filename_ Pattern > or dpkg -- search < filename_ pattern>

$ dpkg -S sites-available
apache2: /etc/apache2/sites-available/default-ssl.conf
apache2: /etc/apache2/sites-available/000-default.conf
nginx-common: /etc/nginx/sites-available
nginx-common: /etc/nginx/sites-available/default
apache2: /etc/apache2/sites-available

reference material

15 Practical Examples of "dpkg commands" for Debian Based Distros
The of Linux software installation management -- dpkg and apt - * detailed explanation

      </div>

Keywords: Linux Ubuntu debian

Added by gevo12321 on Fri, 21 Jan 2022 22:04:48 +0200