Dpkg (Debian Package) is a package management system in Debian and debian based linux distributions like Ubuntu.
Dpkg is actually a low level command line utility to manage packages. It is different from tools like apt-get and gdebi.
Apt-get and Gdebi are more advanced tools that can resolve dependencies and install them so that the main package and work properly.
In this quick tutorial we shall take a look at some basic examples of the dpkg command and how to use it to manage packages on your system.
The dpkg command works on systems like Debian, Ubuntu, Linux Mint and Elementary OS.
Dpkg command examples
1. List all installed packages
This command will list all the installed packages. The information shall be printed in a tabular format with columns for Name, version, architecture and description. The list shall be huge and you can scroll up and down.
$ dpkg -l 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 accountsservice 0.6.55-0ubuntu10 amd64 query and manipulate user account information ii accountwizard 4:19.04.3-0ubuntu1 amd64 wizard for KDE PIM applications account setup ii acl 2.2.53-4 amd64 access control list - utilities ii acpi-support 0.143 amd64 scripts for handling many ACPI events
2. Search installed packages
You can search the list of installed packages for a particular entry and see if it is installed or not.
Search the installed packages for 'apache'
$ dpkg --get-selections | grep 'apache' apache2 install apache2-mpm-prefork install apache2-suexec install apache2-utils install apache2.2-bin install apache2.2-common install libapache-pom-java install libapache2-mod-fcgid install libapache2-mod-php5 install
Or use the same l option to search for installed packages. This is actually easier.
$ dpkg -l php* 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 +++-===============================-====================-====================-==================================================================== un php-doc <none> (no description available) un php-imlib <none> (no description available) un php-kolab-filter <none> (no description available) un php-openid <none> (no description available) un php-pear <none> (no description available) un php-radius-legacy <none> (no description available) ii php5 5.4.6-1ubuntu1.2 all server-side, HTML-embedded scripting language (metapackage) ii php5-cgi 5.4.6-1ubuntu1.2 amd64 server-side, HTML-embedded scripting language (CGI binary) ii php5-cli 5.4.6-1ubuntu1.2 amd64 command-line interpreter for the php5 scripting language ii php5-common 5.4.6-1ubuntu1.2 amd64 Common files for packages built from the php5 source
3. List files installed by a package
To find the path of all files that are installed by a certain package use "L" option with dpkg
$ dpkg -L php5-cli /. /etc /etc/php5 /etc/php5/cli /usr /usr/share /usr/share/man /usr/share/man/man1 /usr/share/man/man1/php5.1.gz /usr/share/doc /usr/share/lintian /usr/share/lintian/overrides /usr/share/lintian/overrides/php5-cli /usr/lib /usr/lib/php5 /usr/lib/php5/20100525 /usr/bin /usr/bin/php5 /etc/php5/cli/conf.d /usr/share/doc/php5-cli
dpkg -i <package.deb> Installs a Debian package file; one that you downloaded manually, for example. dpkg -c <package.deb> Lists the contents of <package.deb>, a .deb file. dpkg -I <package.deb> Extracts package information from <package.deb>, a .deb file. dpkg -r <package> Removes an installed package named <package> dpkg -P <package> Purges an installed package named <package>. The difference between remove and purge is that while remove only deletes data and executables, purge also deletes all configuration files in addition. dpkg -L <package> Gives a listing of all the files installed by <package>. See also dpkg -c for checking the contents of a .deb file. dpkg -s <package> Shows information on the installed package <package>. See also apt-cache show for viewing package information in the Debian archive and dpkg -I for viewing package information extracted from a .deb file. dpkg-reconfigure <package> Reconfigures an installed package, if it uses debconf (debconf provides that consistent configuration interface for package installation). You can reconfigure debconf itself if you want to change the front-end or priority of questions asked. For example, to reconfigure debconf with the dialog front-end, you simply run: dpkg-reconfigure --frontend=dialog debconf echo ``<package> hold'' | dpkg --set-selections Put <package> on hold (command line method) dpkg --get-selections ``<package>'' Get the current status of <package> (command line method) dpkg -S <file> Searches for <file> in package database, telling you which packages have that file in them.
Reconfigure installed packages
Packages can be reconfigured using the dpkg-reconfigure command.
For example reconfiguring phpmyadmin:
$ dpkg-reconfigure phpmyadmin
Those were some basic examples of the dpkg command. In most cases, you would probably not be using the dpkg package for package management since its a low level command and provides only basic functionality of installing or removing .deb packages.
It does not manage repositories and does not find and install dependencies for the main package to work properly.
The other commands like apt-get, aptitude, apt, gdebi should be used for installing and maintaining packages on your system.
If you have any feedback or questions, let us know in the comments below.