15+ dpkg command examples in Linux [Cheat Sheet]

Introduction to dpkg

dpkg is a package management tool to install, build, remove, query and manage packages in Debian-based systems. The primary front-end for dpkg is aptitude. dpkg only works with .deb package files, so you need to have .deb files in your system. The .deb file contains the installation packages of software for Debian-based Linux distributions such as Ubuntu, Linux Mint, Fedora, and Debian.

 

Different examples to use dpkg command

Only users with root privilege can execute dpkg command. You can find .deb packages at debian.org, or you can download using the following command.

Advertisement
# apt-get download package_name

In this article, we will learn to use dpkg command to manage software packages in Debian-based Linux distributions.

 

1. dpkg command to install a package

To install a Debian package, you can use -i or --install option followed by .deb package.

# dpkg -i deb_packagename

OR

# dpkg --install deb_packagename

Sample Output:

dpkg command to install package

 

2. Check if a package is installed or not using dpkg command

-s or --status option prints the status of a package showing if a package is installed or not in your system.

# dpkg -s package_name

OR

Advertisement
# dpkg --status package_name

Sample Output:

dpkg command to check status of package

 

3. Remove an installed package with dpkg command

You can use this command to uninstall a package from the system. It removes an installed package, not a .deb file.

# dpkg -r package_name

OR

# dpkg --remove package_name

Sample Output:

dpkg command to remove package

 

4. Remove an installed package along with configuration files

-r option removes a package but not configuration files. You can use -P or --purge option instead to remove a package along with configuration files.

# dpkg -P package_name

OR

# dpkg --purge package_name

Sample Output:

dpkg command to purge a package

 

5. dpkg command to view the list of installed packages

To get the list of all installed deb packages in your system, you can use this command.

Advertisement
# dpkg -l

Sample Output:

root@golinux:~# 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 a11y-profile-manager-indicator 0.1.10-0ubuntu3 i386 Accessibility Profile Manager - Unity desktop indicator
ii account-plugin-facebook 0.12+16.04.20160126- all GNOME Control Center account plugin for single signon - facebook
ii account-plugin-flickr 0.12+16.04.20160126- all GNOME Control Center account plugin for single signon - flickr
ii account-plugin-google 0.12+16.04.20160126- all GNOME Control Center account plugin for single signon
ii accountsservice 0.6.40-2ubuntu11.3 i386 query and manipulate user account information
ii acl 2.2.52-3 i386 Access control list utilities
ii acpi-support 0.142 i386 scripts for handling many ACPI events
ii appstream 0.9.4-1ubuntu4 i386 Software component index
ii apt 1.2.27 i386 commandline package manager
ii apt-transport-https 1.2.27 i386 https download transport for APT
ii apt-utils 1.2.27 i386 package management related utility programs
ii bzip2 1.0.6-8 i386 high-quality block-sorting file compressor - utilities
...

You can specify the package name and list the particular package only.

root@golinux:~# dpkg -l python

Sample Output:
dpkg command

If you don't recall the package name then you can list all the packages and grep for your package

deepak@ubuntu:~$ dpkg -l | grep python
ri  libpython-stdlib:amd64                     2.7.15~rc1-1                                     amd64        interactive high-level object-oriented language (default python version)
ii  libpython2.7:amd64                         2.7.17-1~18.04ubuntu1.6                          amd64        Shared Python runtime library (version 2.7)
ii  libpython2.7-minimal:amd64                 2.7.17-1~18.04ubuntu1.6                          amd64        Minimal subset of the Python language (version 2.7)
ii  libpython2.7-stdlib:amd64                  2.7.17-1~18.04ubuntu1.6                          amd64        Interactive high-level object-oriented language (standard library, version 2.7)
...

 

6. List contents of deb package with dpkg command

You can use -c or --contents option to list and view the contents of a deb package.

# dpkg -c deb_packagefile

OR

# dpkg --contents deb_packagefile

Sample Output:

dpkg command to view content of package

 

7. dpkg command to get the information of deb package

If you want to get the information of a deb package before installing it, you can use the following command.

# dpkg -I deb_packagename

OR

# dpkg --info deb_packagename

Sample Output:

root@golinux:~# dpkg -I scythe_0.994-3_i386.deb
new debian package, version 2.0.
size 17952 bytes: control archive=831 bytes.
647 bytes, 14 lines control 
466 bytes, 7 lines md5sums 
Package: scythe
Version: 0.994-3
Architecture: i386
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Med Packaging Team <debian-med-packaging@lists.alioth.debian.org>
Installed-Size: 48
Depends: libc6 (>= 2.4), zlib1g (>= 1:1.1.4)
Section: science
Priority: optional
Homepage: https://github.com/vsbuffalo/scythe
Description: Bayesian adaptor trimmer for sequencing reads
Scythe uses a Naive Bayesian approach to classify contaminant substrings in
sequence reads. It considers quality information, which can make it robust in
picking out 3'-end adapters, which often include poor quality bases.

 

8. dpkg command to extract the files of a package

You can use -x option to extract the files contained by a deb package. You need to specify the directory where files are to be extracted.

# dpkg -x deb_packagename /path/to/directory

Sample Output:

dpkg command to extract files of package

-X option will extract and display the filenames contained by a package.

# dpkg -X deb_packagename /path/to/directory

 

9. Unpack the package, but don't configure with dpkg command

--unpack option is used to unpack the package, but it will not configure or install the package.

# dpkg --unpack deb_packagename

Sample Output:

dpkg command to unpack package

Now, let's see the status of a package scythe.

dpkg check status of package

 

10. dpkg command to reconfigure an unpacked package

You can use --configure option to reconfigure a package that was unpacked but not configured yet.

# dpkg --configure package_name

Sample Output:

dpkg command to configure an unpacked package

 

11. Search partially installed packages with dpkg command

-C or --audit option searches for packages that have been installed only partially on your system.

# dpkg -C

OR

# dpkg --audit

Sample Output:

dpkg command to search partially installed packages

 

12. dpkg command to list all files of installed package

You can use -L option to list all files of a particular installed package.

# dpkg -L package_name

Sample Output:

root@golinux:~# dpkg -L gcc
/.
/usr
/usr/bin
/usr/bin/c89-gcc
/usr/bin/c99-gcc
/usr/share
/usr/share/doc
/usr/share/doc/cpp
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/c99-gcc.1.gz
/usr/share/man/man1/c89-gcc.1.gz
/usr/bin/gcc-nm
/usr/bin/gcov
/usr/bin/i686-linux-gnu-gcc
/usr/bin/i686-linux-gnu-gcc-ranlib
/usr/bin/i686-linux-gnu-gcc-ar
/usr/bin/gcc
...

 

13. Search for a filename from installed packages with dpkg command

-S option allows you to search for a filename from installed packages. It prints the list of every file that contains the matching pattern.

# dpkg -S filename_pattern

Sample Output:

root@golinux:~# dpkg -S php
app-install-data: /usr/share/app-install/desktop/slbackup-php:slbackup-php.desktop
app-install-data: /usr/share/app-install/desktop/gphpedit:gphpedit.desktop
humanity-icon-theme: /usr/share/icons/Humanity/mimes/48/gnome-mime-application-x-php.svg
lintian: /usr/share/lintian/checks/phppear.pm
apg: /usr/share/doc/apg/php.tar.gz
humanity-icon-theme: /usr/share/icons/Humanity/mimes/16/gnome-mime-application-x-php.svg
humanity-icon-theme: /usr/share/icons/Humanity/mimes/48/application-x-php.svg
libgtksourceview-3.0-common: /usr/share/gtksourceview-3.0/language-specs/php.lang
unity-asset-pool: /usr/share/icons/unity-icon-theme/places/svg/service-phpdocumentation.svg
app-install-data: /usr/share/app-install/icons/gphpedit.png
...

 

14. Update package information with dpkg command

With option --update-avail, old information is replaced with the available information in the packages file.

# dpkg --update-avail package_name

Sample Output:

root@golinux:~# dpkg --update-avail scythe_0.994-3_i386.deb
Replacing available packages info, using scythe_0.994-3_i386.deb.

 

15. dpkg command to forget uninstalled and unavailable packages

--forget-old-unavail command will automatically forget uninstalled and unavailable packages but only those that do not contain user information such as package selections.

# dpkg --forget-old-unavail

Sample Output:

root@golinux:~# dpkg --forget-old-unavail
dpkg: warning: obsolete '--forget-old-unavail' option; unavailable packages are automatically cleaned up

 

16. Erase the existing information of packages using dpkg command

You can use --clear-avail option to erase the existing information about what packages are available.

$ sudo dpkg --clear-avail

 

Conclusion

dpkg is a command line tool to install, build, remove and manage Debian packages. Although the primary and more user-friendly front-end for dpkg is apt. dpkg itself is controlled entirely via command line parameters, which consist of exactly one action and zero or more options. The action-parameter tells dpkg what to do and options control the behavior of the action in some way.

 

What's Next

15+ rpm command practical examples in Linux

 

Further Reading

man page for dpkg command

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment