dpkg : 10 practical common examples of dpkg command

If you happen to be a Debian or one of its based distros user (like: Ubuntu, Linux Mint, deepin, Elementary OS, Zorin OS, SparkyLinux … etc), you should definitely know the essential uses of dpkg command.

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

1. Install / Upgrade a “.deb” package:

Short syntax: $ dpkg -i PKG.deb
Long syntax: $ dpkg --install PKG.deb
Example:

$ dpkg -i htop.deb
If the package wasn’t installed, it will install a fresh copy of it. Otherwise, it will upgrade the installed package.

2. Install all “.deb” packages in a directory:

Short syntax: $ dpkg -Ri DIR
Long syntax: $ dpkg --recursive --install DIR
Example: 

$ dpkg -Ri ~/deb-pkgs/
Recursively install all regular files matching pattern *.deb found at specified directories and all of its subdirectories. This can be used with -i, -A, --install, --unpack and --avail actions.

3. Remove / Uninstall a package:

Short syntax: $ dpkg -r PKG
Long syntax: $ dpkg --remove PKG
Example: 

$ dpkg -r htop
Remove / Delete an installed package except the configuration files.

4. Completely Remove (Purge) / Uninstall a package:

Short syntax: $ dpkg -P PKG
Long syntax: $ dpkg --purge PKG
Example: 

$ dpkg -P htop
Purge / Completely delete an installed package including its configuration files.

5. List all / Individual installed packages:

Short syntax: $ dpkg -l PKG
Long syntax: $ dpkg --list PKG
Example:

List all packages:

$ dpkg -l
$ dpkg -l | less

List individual package(s):

$ dpkg -l coreutils
$ dpkg -l | grep -iE 'coreutils|perl'
$ dpkg -l coreutils perl
$ dpkg -l | grep -i 'lib*'
If you provide a PACKAGE-NAME to dpkg‘s command, it will list it individually. Otherwise, it will list all the installed packages.

6. List the installed files from a package:

Short syntax: $ dpkg -L PKG
Long syntax: $ dpkg --listfiles PKG
Example: 

$ dpkg -L tmux

7. List the contents of a “.deb” package:

Short syntax: $ dpkg -c PKG.deb
Long syntax: $ dpkg --contents PKG.deb
Example: 

$ dpkg -c ranger.deb
List the files provided (or owned) by the package i.e. List all files inside debian .deb package file, very useful to find where files would be installed.

8. Find out which package does a particular file belong to:

Short syntax: $ dpkg -S FILE
Long syntax: $ dpkg --search FILE
Example: 

$ dpkg -S shred
$ dpkg -S /usr/bin/md5sum
Find out what package owns a particular file.

9. Display details about a package:

Short syntax: $ dpkg -p PKG
Long syntax: $ dpkg --print-avail PKG
Example: 

$ dpkg -p coreutils
Display details about package package group, version, maintainer, Architecture, display depends packages, description etc. You should use apt-cache show PKG instead.

10. Display a package’s status:

Short syntax: $ dpkg -s PKG
Long syntax: $ dpkg --status PKG
Example:

$ dpkg -s htop
Report status of specified package.

 To get more help:

See the manual:

$ man dpkg

Or read it online: dpkg(1)

Leave a Reply

Your email address will not be published.

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