15 Practical Examples of “dpkg commands” for Debian Based Distros

Debian GNU/Linux, the mother Operating System of a number of Linux distributions including Knoppix, Kali, Ubuntu, Mint, etc. uses various package Manager like dpkg, apt, aptitude, synaptic, tasksel, deselect, dpkg-deb and dpkg-split.

dpkg Command Examples

15 dpkg Command Examples

We will be describing each of these briefly before focusing on ‘dpkg‘ command.

APT Command

Apt stands for Advanced Package Tool. It doesn’t deal with ‘deb‘ package and works directly, but works with ‘deb‘ archive from the location specified in the “/etc/apt/sources.list” file.

Read More : 25 Useful Basic Commands of APT-GET Commands

Aptitude

Aptitude is a text based package manager for Debian which is front-end to ‘apt‘, which enables user to manage packages easily.

Synaptic

Graphical package manager which makes it easy to install, upgrade and uninstall packages even to novice.

Tasksel

Tasksel lets the user to install all the relevant packages related to a specific task, viz., Desktop-environment.

Deselect

A menu-driven package management tool, initially used during the first time install and now is replaced with aptitude.

Dpkg-deb

Interacts with Debian archive.

Dpkg-split

Useful in splitting and merging large file into chunks of small files to be stored on media of smaller size like floppy-disk.

Dpkg Command

dpkg is the main package management program in Debian and Debian based System. It is used to install, build, remove, and manage packages. Aptitude is the primary front-end to dpkg.

Some the most commonly used dpkg commands along with their usages are listed here:

1. Install a Package

For installing an “.deb” package, use the command with “-i” option. For example, to install an “.deb” package called “flashpluginnonfree_2.8.2+squeeze1_i386.deb” use the following command.

[[email protected]~]# dpkg -i flashpluginnonfree_2.8.2+squeeze1_i386.deb
Selecting previously unselected package flashplugin-nonfree.
(Reading database ... 465729 files and directories currently installed.)
Unpacking flashplugin-nonfree (from flashplugin-nonfree_3.2_i386.deb) ...
Setting up flashplugin-nonfree (1:3.2) ...
--2013-10-01 16:23:40--  http://fpdownload.macromedia.com/get/flashplayer/pdc/11.2.202.310/install_flash_player_11_linux.i386.tar.gz
Resolving fpdownload.macromedia.com (fpdownload.macromedia.com)... 23.64.66.70
Connecting to fpdownload.macromedia.com (fpdownload.macromedia.com)|23.64.66.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6923724 (6.6M) [application/x-gzip]
Saving to: ‘/tmp/flashplugin-nonfree.FPxQ4l02fL/install_flash_player_11_linux.i386.tar.gz’

2. List all the installed Packages

To view and list all the installed packages, use the “-l” option along with the command.

[[email protected]~]# 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  accerciser                             3.8.0-0ubuntu1           all             interactive Python accessibility explorer for the GNOME desktop
ii  account-plugin-aim                     3.6.4-0ubuntu4.1         i386            Messaging account plugin for AIM
ii  account-plugin-facebook                0.10bzr13.03.26-0ubuntu1 i386            GNOME Control Center account plugin for single signon - facebook
ii  account-plugin-flickr                  0.10bzr13.03.26-0ubuntu1 i386            GNOME Control Center account plugin for single signon - flickr
ii  account-plugin-generic-oauth           0.10bzr13.03.26-0ubuntu1 i386            GNOME Control Center account plugin for single signon - generic OAuth
ii  account-plugin-google                  0.10bzr13.03.26-0ubuntu1 i386            GNOME Control Center account plugin for single signon
rc  account-plugin-identica                0.10bzr13.03.26-0ubuntu1 i386            GNOME Control Center account plugin for single signon - identica
ii  account-plugin-jabber                  3.6.4-0ubuntu4.1         i386            Messaging account plugin for Jabber/XMPP
....

To view a specific package installed or not use the option “-l” along with package-name. For example, check whether apache2 package installed or not.

[[email protected]~]# dpkg -l apache2
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  apache2                                2.2.22-6ubuntu5.1        i386            Apache HTTP Server metapackage

3. Remove a Package

To remove the “.deb” package, we must specify the package name “flashpluginnonfree“, not the original name “flashplugin-nonfree_3.2_i386.deb“. The “-r” option is used to remove/uninstall a package.

[[email protected]~]# dpkg -r flashpluginnonfree
(Reading database ... 142891 files and directories currently installed.) 
Removing flashpluginnonfree ... 
Processing triggers for man-db ... 
Processing triggers for menu ... 
Processing triggers for desktop-file-utils ... 
Processing triggers for gnome-menus ...

You can also use ‘p‘ option in place of ‘r’ which will remove the package along with configuration file. The ‘r‘ option will only remove the package and not configuration files.

[[email protected]~]# dpkg -p flashpluginnonfree

4. View the Content of a Package

To view the content of a particular package, use the “-c” option as shown. The command will display the contents of a “.deb” package in long-list format.

[[email protected]~]# dpkg -c flashplugin-nonfree_3.2_i386.deb
drwxr-xr-x root/root         0 2012-12-14 22:54 ./
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/bin/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/lib/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/lib/mozilla/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/lib/mozilla/plugins/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/lib/flashplugin-nonfree/
-rw-r--r-- root/root      3920 2009-09-09 22:51 ./usr/lib/flashplugin-nonfree/pubkey.asc
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/man/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/man/man8/
-rw-r--r-- root/root       716 2012-12-14 22:54 ./usr/share/man/man8/update-flashplugin-nonfree.8.gz
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/applications/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/icons/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/icons/hicolor/
drwxr-xr-x root/root         0 2012-12-14 22:54 ./usr/share/icons/hicolor/24x24/
....

5. Check a Package is installed or not

Using “-s” option with package name, will display whether an deb package installed or not.

[[email protected]~]# dpkg -s flashplugin-nonfree
Package: flashplugin-nonfree
Status: install ok installed
Priority: optional
Section: contrib/web
Installed-Size: 177
Maintainer: Bart Martens <[email protected]>
Architecture: i386
Version: 1:3.2
Replaces: flashplugin (<< 6)
Depends: debconf | debconf-2.0, wget, gnupg, libatk1.0-0, libcairo2, libfontconfig1, libfreetype6, libgcc1, libglib2.0-0, libgtk2.0-0 (>= 2.14), libnspr4, libnss3, libpango1.0-0, libstdc++6, libx11-6, libxext6, libxt6, libcurl3-gnutls, binutils
Suggests: iceweasel, konqueror-nsplugins, ttf-mscorefonts-installer, ttf-dejavu, ttf-xfree86-nonfree, flashplugin-nonfree-extrasound, hal
Conflicts: flashplayer-mozilla, flashplugin (<< 6), libflash-mozplugin, xfs (<< 1:1.0.1-5)
Description: Adobe Flash Player - browser plugin
...

6. Check the location of Packages installed

To list location of files to be installed to your system from package-name.

[[email protected]~]# dpkg -L flashplugin-nonfree
/.
/usr
/usr/bin
/usr/lib
/usr/lib/mozilla
/usr/lib/mozilla/plugins
/usr/lib/flashplugin-nonfree
/usr/lib/flashplugin-nonfree/pubkey.asc
/usr/share
/usr/share/man
/usr/share/man/man8
/usr/share/man/man8/update-flashplugin-nonfree.8.gz
/usr/share/applications
/usr/share/icons
/usr/share/icons/hicolor
...

7. Install all Packages from a Directory

Recursively, install all the regular files matching pattern “*.deb” found at specified directories and all of its subdirectories. This can be used with “-R” and “–install” options. For example, I will install all the “.deb” packages from the directory called “debpackages“.

[[email protected]~]# dpkg -R --install debpackages/
(Reading database ... 465836 files and directories currently installed.)
Preparing to replace flashplugin-nonfree 1:3.2 (using .../flashplugin-nonfree_3.2_i386.deb) ...
Unpacking replacement flashplugin-nonfree ...
Setting up flashplugin-nonfree (1:3.2) ...
Processing triggers for man-db ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for gnome-menus ...

8. Unpack the Package but dont’ Configure

Using action “–unpack” will unpack the package, but it will don’t install or configure it.

[[email protected]~]# dpkg --unpack flashplugin-nonfree_3.2_i386.deb
(Reading database ... 465836 files and directories currently installed.)
Preparing to replace flashplugin-nonfree 1:3.2 (using flashplugin-nonfree_3.2_i386.deb) ...
Unpacking replacement flashplugin-nonfree ...
Processing triggers for man-db ...
Processing triggers for bamfdaemon ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for gnome-menus ...

9. Reconfigure a Unpacked Package

The option “–configure” will reconfigure a already unpacked package.

[[email protected]~]# dpkg --configure flashplugin-nonfree
Setting up flashplugin-nonfree (1:3.2) ...

10. Replace available Package information

The “–-update-avail” option replace the old information with the available information in the Packages file.

[[email protected]~]# dpkg –-update-avail package_name

11. Erase Existing Available information of Package

The action “–clear-avaial” will erase the current information about what packages are available.

[[email protected]~]# dpkg –-clear-avail

12. Forget Uninstalled and Unavailable Packages

The dpkg command with option “–forget-old-unavail” will automatically forget uninstalled and unavailable packages .

[[email protected]~]# dpkg --forget-old-unavail

13. Display dpkg Licence

[[email protected]~]# dpkg --licence

14. Display dpkg Version

The “–version” argument will display dpkg version information.

[[email protected]~]# dpkg –version
Debian `dpkg' package management program version 1.16.10 (i386).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.

15. Get all the Help about dpkg

The “–help” option will display a list of available options of dpkg command.

[[email protected]~]# 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
  --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.
...

That’s all for now. I’ll soon be here again with another interesting article. If I’ve missed any command in the list do let me know via comments. Till then, Stay tuned and Keep connected to Tecmint. Like and share us and help us spread. Don’t forget to mention your valuable thoughts in comment.

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

10 Responses

  1. Hedley Finger says:

    I would like to remove some of the columns from the output of dpkg -l. I would also like to list just the packages I installed manually after a fresh Ubuntu installation or upgrade.

  2. aptee says:

    I’ve installed cinnamon on my raspi 3 I’m a newbie, how do I extract it? where is it, I’ve tried all the above but to no avail.

  3. Khach says:

    I have got this error. How to solve it?

    Setting up gnome-menus (3.13.3-9) …
    /var/lib/dpkg/info/gnome-menus.postinst: 10: /var/lib/dpkg/info/gnome-menus.postinst: gnome-menus-blacklist: not found
    dpkg: error processing package gnome-menus (–configure):
    subprocess installed post-installation script returned error exit status 127
    Errors were encountered while processing:
    gnome-menus
    E: Sub-process /usr/bin/dpkg returned an error code (1)

  4. riajul Islam says:

    this is a perfect article.

  5. Raj says:

    To remove a package with configuration I think it is “-P” in caps. which is –purge. Removes a package including configuration files.

  6. Martin Goik says:

    An example getting the package owning a specific file or directory might be helpful i.e.:

    dpkg -S /usr/bin/nice
    –>coreutils: /usr/bin/nice

    At least I need this one occasionally for administrative purposes.

  7. visoos says:

    GREAT!

    THANX.

  8. James Mac says:

    @LinuxEnthusiastic:

    1. dkpg is still a pre-requisite for passing LPIC-1 certification.

    2. It’s largely distro-neutral. Sure, I can bypass dpkg on my Ubuntu machine by just using Ubuntu Software Centre (built over Synaptic, which is built over APT, which is built over dpkg), but the day I hit a non-Ubuntu Debian, I’m stuffed – unless I go back to source.

    3. APT may be smarter (do you really mean “more user-friendly”?) but I think dpkg gives you more control, and for an administrator that would matter more.

  9. LinuxEnthusiastic says:

    Who use dpkg??

    well APT is much smarter.

  10. FossEnthusiastic says:

    Well I Think, This article could have been a bit more Elaborative.

Leave a Reply to Martin Goik Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.