Debian Linux and other Debian based Linux distributions, such as Ubuntu and Linux Mint, use dpkg as a package manager.

You might be thinking, "I thought those distributions used apt - that's what I always use to install packages." That's true, apt is also a package manager, but really it's just passing off tasks to dpkg in the background. apt and other package managers on Debian usually just utilize dpkg to install packages or perform similar tasks.

Package manager commands like those from apt or apt-get are meant for end-users. They're easy to use and are very familiar to most Linux users. dpkg is low-level tool that is more geared towards use by the system, but we can still use it with the dpkg command.

In this guide, we'll go over various dpkg command examples to help you learn to use the tool and manage packages on your Debian or Debian based system.

In this tutorial you will learn:
  • How to install .deb packages with dpkg
  • How to use dpkg command through examples
Using dpkg command on Linux
Using dpkg command on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro with dpkg
Software dpkg
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to use dpkg command through examples


SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


The easiest way to learn about the dpkg command is through examples. To get started, use some of the following commands on your own system, and you'll eventually have it mastered and be able to use it to install deb files or reconfigure packages, etc.

  1. The most common use for dpkg is probably to install .deb files, since apt is ordinarily used to install packages from repositories. Once you have downloaded a deb file, you can use the -i (install) option to install it.
    $ dpkg -i package-name.deb
    
  2. To see a full list of installed packages on your system, you can use the -l (list) option. This will give you extra details like the version of the package, system architecture, and a description.
    $ dpkg -l
    
  3. Listing all installed packages with dpkg
    Listing all installed packages with dpkg


  4. If you want to search for an installed package by its name, just specify your search string after the -l option.
    $ dpkg -l nmap
    ...
    ||/ Name           Version            Architecture Description
    +++-==============-==================-============-=================================
    ii  nmap           7.80+dfsg1-2build1 amd64        The Network Mapper
    
  5. You can remove a package by using the -r (remove) option. Note that this will leave behind configuration files, but uninstall the program.
    $ sudo dpkg -r package-name
    
  6. You can purge a package, which will uninstall the software and delete all of its configuration files instead of leaving them behind, by using the -P (Purge) option.
    $ sudo dpkg -P package-name
    
  7. To quickly check whether a package is installed or not, you can use the -s (status) option.
    $ dpkg -s nmap
    
  8. Checking to see if a package is installed, and seeing detailed information about the package
    Checking to see if a package is installed, and seeing detailed information about the package


  9. Use dpkg to examine the contents of a .deb file by appending the -c (contents) option.
    $ dpkg -c package-name.deb
    
  10. You can unpack a .deb file to see and manipulate its contents by using the --unpack option.
    $ dpkg --unpack package-name.deb
    
  11. If you make changes to the unpacked .deb files, you can repackage everything into a .deb file by using the --configure option.
    $ sudo dpkg --configure package-name
    
  12. If a package has already been installed and configured, you will probably have to opt for the dpkg-reconfigure command if you wish to configure its settings further`.
    $ sudo dpkg-reconfigure unattended-upgrades
    

  13. SUBSCRIBE TO NEWSLETTER
    Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


    Reconfiguring an installed package by using the dpkg-reconfigure command
    Reconfiguring an installed package by using the dpkg-reconfigure command

This should be the majority of the dpkg commands that you'll ever need to know, although even more options exist. If you'd like to delve even further, check the man page for more options.

$ man dpkg

Closing Thoughts

In this guide, we saw how to use dpkg, the Debian package manager, through command line examples. We covered installing deb files, removing and purging packages, as well as listing, unpacking, and configuring deb files. Most likely, these will be all the dpkg commands you will need to familiarize yourself with. dpkg usually only needs learned after high level wrappers like apt have been mastered first.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.