The Beginner’s Guide to the dpkg Command in Debian-Based Linux Distro

debian-dpkg-command-featured

Every Linux distribution comes with a specific package manager. For Debian or Debian-based distro, the default package manager is “apt” or “apt-get” or the graphical Software Center/Synaptic. These package managers, in turn, rely on the low-level tool dpkg to manage software packages.

In this article we show you the basics of Debian package management and how to manage software packages using dpkg.

Understanding Debian Package Management

The Debian package management employs a couple of diverse package management tools – such as “apt-get,” “aptitude,” “dpkg,” “apt-file,” “dselect,” “tasksel,” and “gdebi” – to manage software on the system. These tools are known as package managers. Some, if not all, of these tools utilize the low-level tool dpkg to provide high-level functionality.

The dpkg command allows you to easily install and remove software and manipulate and upgrade software in a seamless fashion.

Usage of dpkg Command

How to Install a Software/Package

You can make use of dpkg to install software by using the following command. This command can also upgrade a package if it is already installed.

dpkg -i package_name.deb

The above command requires you to have a physical .deb file on your computer.

List Currently Installed Packages

To list or display currently installed packages on a Debian-based distro, you can use the commands below:

dpkg -l search_pattern

list-packages-installed

If you want to list all installed packages, just omit [search_pattern].

dpkg -l

Remove Installed Packages

If you have already installed a package but do not use it anymore, you can use the following command to uninstall it. This command removes the entire package except configuration files.

dpkg -r package_name.deb

List Content of a Package

You can use the commands below to list content of a package on your Linux computer:

dpkg --contents package_name.deb

You can also use -c in place of --contents.

dpkg -c package_name.deb

Check Whether a Package Is Installed or Not

Assuming you want to check whether you have installed a specific package on your computer, use the following command to check.

dpkg -s package_name.deb

check-packages

Check the Location of the Installed Package

If you just want to find out the location where the package will be installed, use the -L flag.

dpkg -L package_name.deb

Display Detailed Information About a Package

This command displays or shows detailed information about a package.

dpkg -p package_name.deb

Install Multiple Packages Simultaneously

If you have a number of deb files that you want to install, you can run the following command to install them all at one go. Do note that for this to work, you have to place all the .deb files in the same folder.

dpkg -R --install /deb-files-location/

Unpack a deb Package

Sometimes you might want to unpack a deb package so you can make changes to its files. Use this command to unpack a deb file.

dpkg --unpack package_name.deb

Reconfigure an Unpacked deb Package

After you have made changes to the files, use this command to configure and repack it into a deb file for installation.

dpkg --configure pacakge_name

In Need of Extra Information About dpkg Commands?

If you want to know more about dpkg commands, you can use the command below. It displays detailed information about dpkg commands and options.

dpkg --help

Conclusion

Most of the Debian-based package managers rely solely on dpkg to get things done. With the above commands, you can get down to the basics when all other installation methods fail.

Image credit: Debian – Wooden 3D rendered letters/message by christitzeimaging.com/Shutterstock

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Michael Aboagye

Michael wears many hat in the opensource industry. He is based in Accra, Ghana. He revels in anything Linux and Devops.