15 Useful ‘dpkg’ Commands for Debian/Ubuntu Users

Debian GNU/Linux, the foundational operating system for several Linux distributions including Knoppix, Kali, Ubuntu, Mint, etc., uses various package managers such as dpkg, apt, apt-get, aptitude, synaptic, tasksel, deselect, dpkg-deb, and dpkg-split.

We will briefly describe each of these package managers before focusing on the ‘dpkg‘ command.

Command Description
apt apt, short for advanced package tool in Debian-based systems used to install, remove, and update software packages.
aptitude aptitude is a text-based package manager for Debian which is a front-end to ‘apt‘, enabling users to manage packages easily.
synaptic synaptic is a graphical package manager that makes it easy to install, upgrade, and uninstall packages even for novices.
tasksel tasksel allows users to install all relevant packages related to a specific task, such as a desktop environment.
deselect deselect is a menu-driven package management tool initially used during the first install and is now replaced with aptitude.
dpkg-deb dpkg-deb interacts with Debian archives.
dpkg-split dpkg-split is useful for splitting and merging large files into chunks of smaller files to be stored on media of smaller sizes, such as floppy disks.

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

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

1. Install a Package on Ubuntu

To install a package using dpkg, you need to download .deb package file from the following official package repository sites for Debian and Ubuntu-based distributions.

Once downloaded, you can install it using the -i option followed by the name of the .deb package file.

sudo dpkg -i 2048-qt_0.1.6-2+b2_amd64.deb
Install Deb Package
Install Deb Package

2. List Installed Packages on Ubuntu

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

dpkg -l
List Installed Deb Packages
List Installed Deb Packages

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

dpkg -l apache2
Check Package Installation
Check Package Installation

3. Remove a Package on Ubuntu

To remove the “.deb” package, we must specify the package name “2048-qt” with the “-r” option, which is used to remove/uninstall a package.

sudo dpkg -r 2048-qt
Remove Deb Package
Remove Deb Package

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

[root@tecmint~]# dpkg -p flashpluginnonfree

4. View Contents of a .deb Package

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

dpkg -c 2048-qt_0.1.6-2+b2_amd64.deb
View Contents of Deb Package
View Contents of Deb Package

5. Check Status of Deb Package Installation

Using “-s” option with the package name will display whether a deb package is installed or not.

dpkg -s 2048-qt
Check Deb Package Installation
Check Deb Package Installation

6. List Files Installed by Deb Package

To list the location of all the files installed by a particular package use the -L option as shown.

dpkg -L 2048-qt
List Files Installed by Deb Package
List Files Installed by Deb Package

7. Install Multiple Deb Packages from a Directory

Recursively install all .deb files found in specified directories and all of their subdirectories, use the '-R' and '--install' options.

For example, to install all '.deb' packages from the directory named ‘debpackages‘.

sudo dpkg -R --install debpackages
Install All Deb Packages
Install All Deb Packages

8. Extract Contents of a Deb Package

To extract the contents of a .deb package but does not configure the package, use the --unpack option.

sudo dpkg --unpack 2048-qt_0.1.6-2+b2_amd64.deb
Extract Contents of Deb Package
Extract Contents of Deb Package

9. Reconfigure a Unpacked Deb Package

To configure a package that has been unpacked but not yet configured, use the “--configure” option as shown.

sudo dpkg --configure flashplugin-nonfree

10. Updating Package Information in System Database

The “–-update-avail” option replaces the old information with the available information for the package file in the package management system’s database.

sudo dpkg --update-avail package_name

11. Delete Information of Package

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

sudo dpkg –-clear-avail

12. Forget Uninstalled and Unavailable Packages

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

sudo dpkg --forget-old-unavail

13. Display dpkg Licence

dpkg --licence

14. Display dpkg Version

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

dpkg –version

15. View dpkg Help

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

dpkg –help

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 with us and help us spread. Don’t forget to mention your valuable thoughts in a comment.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Avishek
A Passionate GNU/Linux Enthusiast and Software Developer with over a decade in the field of Linux and Open Source technologies.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

11 Comments

Leave a Reply
  1. 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.

    Reply
  2. 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.

    Reply
  3. 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)

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

    Reply
  5. 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.

    Reply
  6. @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.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.