How to: Examples of dpkg commands for Debian Based Distros

dpkg is the software at the base of the package management system in the free operating system Debian and its numerous derivatives. dpkg is used to install, remove, and provide information about .deb packages.

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.

dpkg -i flashpluginnonfree_2.8.2+squeeze1_i386.deb

List all the installed Packages

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

dpkg -l

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.

dpkg -l apache2

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.

dpkg -r flashpluginnonfree

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.

dpkg -P flashpluginnonfree

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.

dpkg -c flashplugin-nonfree_3.2_i386.deb

Check a Package is installed or not

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

dpkg -s flashplugin-nonfree

Check the location of Packages installed

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

dpkg -L flashplugin-nonfree

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

dpkg -R --install debpackages/

Unpack the Package but not Configure

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

dpkg --unpack flashplugin-nonfree_3.2_i386.deb

Configure an Unpacked Package

The option –configure will configure a package which has been unpacked but not yet configured.

dpkg --configure flashplugin-nonfree

Replace available Package information

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

dpkg --update-avail package_name

Erase Existing Available information of Package

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

dpkg --clear-avail

Search and display filenames related to an installed Package

The -S option will tell which package a file was installed with.

dpkg -S uuencode
apache2.2-common: /usr/share/apache2/icons/uuencoded.png
sharutils: /usr/share/man/man1/uuencode.1.gz
sharutils: /usr/bin/uuencode
sharutils: /usr/share/man/man5/uuencode.5.gz
apache2.2-common: /usr/share/apache2/icons/uuencoded.gif


dpkg -S /usr/bin/uudecode
sharutils: /usr/bin/uudecode

Extract the files from a Package

Use -x to extract the files from a .deb package.

dpkg -x flashplugin-nonfree_3.2_i386.deb directory/

Remove left over config files

dpkg --list | grep '^rc'
dpkg --list | grep '^rc' | awk '{ print $2 }' | xargs dpkg -P

Leave a Reply

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