Linux Ubuntu dpkg command details

Keywords: Linux Ubuntu

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. The main and more friendly front end of dpkg is aptitude. Dpkg itself is completely controlled by command line parameters, which contain only one action and zero or more options. Action parameters tell dpkg what to do, and options control the behavior of the action in some way.

apt is a yum tool similar to red hat system, which can solve the dependency of deb package by itself. apt Command Reference Linux apt command

Install software

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.

dpkg command details

dpkg -i manually installs a software package (this command does not solve the dependency problem before the software package). If you encounter a software dependency problem when installing a software package, you can use apt get - f install to solve the dependency problem
   
dpkg --info "software package name" -- lists the package name after unpacking the software package

dpkg -l -- lists all the packages in the current system. It can be used with the parameter less and viewed on a split screen. (similar to rpm -qa)

   dpkg -l <package_ Name > query package information
   
dpkg -l |grep -i "package name" -- view the package associated with "package name" in the system

dpkg -s queries the details of installed packages

dpkg -L query the location of the installed software package in the system. (similar to rpm -ql)

dpkg -S queries which software package a file in the system belongs to. (similar to rpm -qf)

dpkg -I queries the details of deb package. After a software package is downloaded locally, see whether it is installed or not

dpkg -r uninstalls the package. It is not completely uninstalled. Its configuration file still exists

dpkg -P uninstall all (but it still can't solve the problem of software package dependency)

dpkg -reconfigure

In terms of package query, dpkg query has the same function as dpkg. For details, please refer to: Dpkg query command

Example

Software installation

$ 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 ...

Query vim package information

$ dpkg -l vim
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version             Architecture Description
+++-==============-===================-============-=================================
ii  vim            2:8.1.2269-1ubuntu5 amd64        Vi IMproved - enhanced vi editor

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 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 (pattern)
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

dpkg parameter

root@Ubuntu20.04:~# dpkg --help
Usage: dpkg [<option> ...] <command>

Commands:
  -i|--install       <.deb file name>... | -R|--recursive <directory>...
  --unpack           <.deb file name>... | -R|--recursive <directory>...
  -A|--record-avail  <.deb file name>... | -R|--recursive <directory>...
  --configure        <package>... | -a|--pending
  --triggers-only    <package>... | -a|--pending
  -r|--remove        <package>... | -a|--pending
  -P|--purge         <package>... | -a|--pending
  -V|--verify [<package>...]       Verify the integrity of package(s).
  --get-selections [<pattern>...]  Get list of selections to stdout.
  --set-selections                 Set package selections from stdin.
  --clear-selections               Deselect every non-essential package.
  --update-avail [<Packages-file>] Replace available packages info.
  --merge-avail [<Packages-file>]  Merge with info from file.
  --clear-avail                    Erase existing available info.
  --forget-old-unavail             Forget uninstalled unavailable pkgs.
  -s|--status [<package>...]       Display package status details.
  -p|--print-avail [<package>...]  Display available version details.
  -L|--listfiles <package>...      List files 'owned' by package(s).
  -l|--list [<pattern>...]         List packages concisely.
  -S|--search <pattern>...         Find package(s) owning file(s).
  -C|--audit [<package>...]        Check for broken package(s).
  --yet-to-unpack                  Print packages selected for installation.
  --predep-package                 Print pre-dependencies to unpack.
  --add-architecture <arch>        Add <arch> to the list of architectures.
  --remove-architecture <arch>     Remove <arch> from the list of architectures.
  --print-architecture             Print dpkg architecture.
  --print-foreign-architectures    Print allowed foreign architectures.
  --assert-<feature>               Assert support for the specified feature.
  --validate-<thing> <string>      Validate a <thing>'s <string>.
  --compare-versions <a> <op> <b>  Compare version numbers - see below.
  --force-help                     Show help on forcing.
  -Dh|--debug=help                 Show help on debugging.

  -?, --help                       Show this help message.
      --version                    Show the version.

Assertable features: support-predepends, working-epoch, long-filenames,
  multi-conrep, multi-arch, versioned-provides.

Validatable things: pkgname, archname, trigname, version.

Use dpkg with -b, --build, -c, --contents, -e, --control, -I, --info,
  -f, --field, -x, --extract, -X, --vextract, --ctrl-tarfile, --fsys-tarfile
on archives (type dpkg-deb --help).

Options:
  --admindir=<directory>     Use <directory> instead of /var/lib/dpkg.
  --root=<directory>         Install on a different root directory.
  --instdir=<directory>      Change installation dir without changing admin dir.
  --path-exclude=<pattern>   Do not install paths which match a shell pattern.
  --path-include=<pattern>   Re-include a pattern after a previous exclusion.
  -O|--selected-only         Skip packages not selected for install/upgrade.
  -E|--skip-same-version     Skip packages whose same version is installed.
  -G|--refuse-downgrade      Skip packages with earlier version than installed.
  -B|--auto-deconfigure      Install even if it would break some other package.
  --[no-]triggers            Skip or force consequential trigger processing.
  --verify-format=<format>   Verify output format (supported: 'rpm').
  --no-debsig                Do not try to verify package signatures.
  --no-act|--dry-run|--simulate
                             Just say what we would do - don't do it.
  -D|--debug=<octal>         Enable debugging (see -Dhelp or --debug=help).
  --status-fd <n>            Send status change updates to file descriptor <n>.
  --status-logger=<command>  Send status change updates to <command>'s stdin.
  --log=<filename>           Log status changes and actions to <filename>.
  --ignore-depends=<package>,...
                             Ignore dependencies involving <package>.
  --force-...                Override problems (see --force-help).
  --no-force-...|--refuse-...
                             Stop when problems encountered.
  --abort-after <n>          Abort after encountering <n> errors.

Comparison operators for --compare-versions are:
  lt le eq ne ge gt       (treat empty version as earlier than any version);
  lt-nl le-nl ge-nl gt-nl (treat empty version as later than any version);
  < << <= = >= >> >       (only for compatibility with control file syntax).

Use 'apt' or 'aptitude' for user-friendly package management.

reference material

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

Original text: https://www.jianshu.com/p/2ec0f4b945a2

Posted by misty on Wed, 10 Nov 2021 12:10:57 -0800