How to use dpkg command in Ubuntu system

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

install software

When using the dpkg command to install the software, you can use the -i option and specify the path of the deb installation package. It is different from another package management tool apt-get (Advanced Package Tool) under Ubuntu.
The apt-get command does not directly manipulate the deb installation package file, but downloads and installs the software package from the software mirror source defined in the /etc/apt/sources.list configuration file. You only need to specify the software when using it. Name (or version number can also be appended).

apt-get command to install the software:
$ apt-get install

The dpkg command installs the software:
$ dpkg -i

Therefore, dpkg is mainly used to install the deb software package that has been downloaded to the local, or to manage the installed software. And apt-get can download and install software directly from the remote software warehouse.

$ sudo apt-get install emacs
Reading package list...carry out
Analyzing the dependency tree of the package
Reading status information...carry out
The following software will be installed at the same time: 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] software packages will be installed: emacs emacs-bin-common emacs-common emacs-el emacs-gtk libm17n-0
 libotf0 m17n-db
0 packages have been upgraded, 8 packages have been newly installed, and 0 packages have to be uninstalled. 115 packages have not been upgraded. Need to download 34.4
$ sudo dpkg -i fping_4.2-1_amd64.deb(Reading database...There are currently 252654 files and directories installed in the system.)
Ready to decompress fping_4.2-1_amd64.deb  ...
Unpacking fping(4.2-1)And overwrite(4.2-1)...
Setting up fping(4.2-1)...
Processing for man-db(2.8.5-2)Trigger...
List installed software

You can use the dpkg -l command to list the software installed in the current system and the status of the software package. Such as:

$ dpkg -l
Desired state=unknown(u)/installation(i)/delete(r)/Clear(p)/maintain(h)|status=未installation(n)/已installation(i)/Save configuration(c)/Unzip only(U)/Configuration failed(F)/不完全installation(H)/Trigger wait(W)/Trigger pending(T)|/error?=(no)/Reinstall(R)(Status, error: uppercase=malfunction)||/Name version architecture description
+++-=============================================-===================================-============-===============================================================================
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 ofGNOME(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 this command indicates the installation and configuration status of the software package, and its format is as follows:
Expected State|Current State|Error
The expected state has the following

The current status is as follows:

There are several error states:

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

View packages in the 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 the dpkg -l command to filter out packages whose names contain the specified pattern.


$ dpkg -l "nginx*"
Desired state=unknown(u)/installation(i)/delete(r)/Clear(p)/maintain(h)|status=未installation(n)/已installation(i)/Save configuration(c)/Unzip only(U)/Configuration failed(F)/不完全installation(H)/Trigger wait(W)/Trigger pending(T)|/error?=(no)/Reinstall(R)(Status, error: uppercase=malfunction)||/Name version architecture description
+++-==============-===============-============-=========================================================
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      <no><no>(no描述)
un  nginx-extras   <no><no>(no描述)
un  nginx-full     <no><no>(no描述)
un  nginx-light    <no><no>(no描述)

Uninstall software

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


$ sudo dpkg -r vim(Reading database...There are currently 252653 files and directories installed in the system.)
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)
have to be aware of is,-The r option will only remove the specified package without affecting its configuration file.

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         02019-02-2006:27./usr/
drwxr-xr-x root/root         02019-02-2006:27./usr/bin/-rwxr-xr-x root/root     521282019-02-2006:27./usr/bin/fping
drwxr-xr-x root/root         02019-02-2006:27./usr/share/
drwxr-xr-x root/root         02019-02-2006:27./usr/share/bug/-rwxr-xr-x root/root       1182017-06-1905:19./usr/share/bug/fping
drwxr-xr-x root/root         02019-02-2006:27./usr/share/doc/
drwxr-xr-x root/root         02019-02-2006:27./usr/share/doc/fping/-rw-r--r-- root/root       4952017-09-0608:00./usr/share/doc/fping/NEWS.Debian.gz
- rw-r--r-- root/root      16152019-02-2006:27./usr/share/doc/fping/changelog.Debian.gz
- rw-r--r-- root/root      34452017-12-0704:09./usr/share/doc/fping/copyright
drwxr-xr-x root/root         02019-02-2006:27./usr/share/lintian/
drwxr-xr-x root/root         02019-02-2006:27./usr/share/lintian/overrides/-rw-r--r-- root/root        412017-06-1905:19./usr/share/lintian/overrides/fping
drwxr-xr-x root/root         02019-02-2006:27./usr/share/man/
drwxr-xr-x root/root         02019-02-2006:27./usr/share/man/man8/-rw-r--r-- root/root      57332019-02-2006:27./usr/share/man/man8/fping.8.gz
- rw-r--r-- root/root      15122019-02-2006:27./usr/share/man/man8/fping6.8.gz
lrwxrwxrwx root/root         02019-02-2006: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 <[email protected]>
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 <[email protected]>
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 packages that contain 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

Recommended Posts

How to use dpkg command in Ubuntu system
How to use hanlp in ubuntu
How to configure TensorFlow use environment in Ubuntu
How to open the ubuntu system in win10
How to configure /var/log/messages in Ubuntu system log
How to use Putty to log in to ubuntu installed in VirtualBox
How to modify time zone and time in ubuntu system
How to install Helm in Ubuntu
How to install mysql in Ubuntu 14.04
How to install mysql in Ubuntu 14.04
How to use SQLite in Python
How to control the ubuntu system in win10 through ssh
How to add swap partition in Ubuntu
How to easily compile openJDK in Ubuntu
How to use and and or in Python
How to install cuda10.1 driver in Ubuntu
How to add users to Sudoers in Ubuntu
How to delete redundant kernels in Ubuntu
How to delete redundant kernels in Ubuntu
How to use Samba server on Ubuntu 16.04
How to install ROS Noetic in Ubuntu20.04
How to set static IP in ubuntu14.04
How to modify software source in Ubuntu 7.10
How to open root account in Ubuntu20.04
How to hide applications in Ubuntu Dash?
How to use Prometheus to monitor your Ubuntu 14.04 server
How to use the zip function in Python
How to upgrade to Ubuntu 20.04
How to use Nginx&#39;s map module on Ubuntu 16.04
Use the command to solve the Ubuntu projector problem:
How to install and use Docker on Ubuntu 20.04
Use supervisor in ubuntu
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to use the format function in python
How to use Docker data volumes on Ubuntu 14.04
Use Ubuntu and windows system in virtual machine
How to use code running assistant in python
How to install and use Composer on Ubuntu 20.04
[Practice] How to install python3.6 on Ubuntu system
How to install and use BaasBox on Ubuntu 14.04
How to use Jenkins to build automatically on Ubuntu
How to install and use PostgreSQL on Ubuntu 16.04
Introduction to the use of Hanlp in ubuntu
Use command to clear specific hostname in CentOS7
How to upgrade to Ubuntu 20.04
How to install and use Docker on Ubuntu 16.04
How to install Hadoop in standalone mode on Ubuntu 18.04
How to use LVM to manage storage devices on Ubuntu 18.04
How to create and use MongoDB backups on Ubuntu 14.04
Use the command line to detect the Ubuntu version method
How to install and use MySQL Workbench on Ubuntu 18.04
How to view detailed network routing table in Ubuntu
Example of how to modify ip address in Ubuntu20.04
How to install theano and keras on ubuntu system
How to create a Python virtual environment in Ubuntu 14.04
How to repair a damaged Ubuntu system without reinstalling
Teach you how to install Ubuntu system enhancement tools
Use of Anaconda in Ubuntu
How to use python tuples