The dpkg command in Linux: management of .deb packages

Introduction

In the ecosystem of Debian-based distributions, handling .deb packages is a daily task for administrators and advanced users. Although tools like APT or aptitude simplify dependency resolution, understanding the dpkg command allows you to work directly with package files and resolve situations where high-level managers fail.

What is dpkg?

dpkg is the low-level package manager of the Debian system. Its main function is to install, remove, upgrade, and query .deb packages, but it does not automatically resolve dependencies. Each operation performed by dpkg is recorded in the database located at /var/lib/dpkg, allowing the system to know which packages are present and in what state.

Advantages and limitations

Among its advantages is the ability to work with local packages without needing repositories, which is useful for testing custom builds or recovering damaged packages. On the other hand, its main limitation is the lack of dependency resolution: if you try to install a package that requires missing libraries, dpkg will fail and leave the package in state unpacked or half‑configured, requiring manual intervention.

Basic commands

  • Install a package: sudo dpkg -i paquete_nombre.deb
  • Remove a package: sudo dpkg -r nombre_paquete (removes leaving configuration files) or sudo dpkg -P nombre_paquete (complete purge).
  • Check status: dpkg -l | grep nombre shows whether it is installed, its version, and description.
  • Reconfigure a package: sudo dpkg-reconfigure nombre_paquete useful after changing configuration options.
  • Show detailed information: dpkg -s nombre_paquete indicates version, architecture, dependencies, and status.
  • List files of a package: dpkg -L nombre_paquete shows all files installed by that package.

Practical examples

Suppose you have a printer driver downloaded from the manufacturer’s site in .deb format. To install it:

sudo dpkg -i descargas/controlador-impresora_1.2.3_amd64.deb

If dpkg reports missing dependencies, you can complete the installation with:

sudo apt-get install -f

This command invokes APT to satisfy pending dependencies.

To remove an application you no longer need and also delete its configuration files:

sudo dpkg -p nombre_aplicacion
sudo dpkg -P nombre_aplicacion

Finally, to check which version of the Linux kernel is installed:

dpkg -l | grep linux-image

Best practices and troubleshooting

  • Always check the dpkg log at /var/log/dpkg.log when an installation fails; there you will find detailed error messages.
  • Before installing a .deb package from an unknown source, verify its signature or checksum to avoid security risks.
  • If a package is left in the half‑installed state, run sudo dpkg --configure -a to attempt to complete the pending configuration.
  • Use apt-mark hold to prevent automatic updates from replacing a version you manually installed with dpkg.
  • In server environments, combine dpkg with automation scripts that check the return code ($?) and act accordingly.

Conclusion

Although high-level tools like APT are the most convenient option for everyday package management, dpkg remains the underlying pillar that provides precise control over each .deb file. Mastering its commands and understanding its limitations allows you to install, troubleshoot, and recover packages in scenarios where automated managers are insufficient, making you a more versatile and secure Linux administrator.

This post is also available in ESPAÑOL.

Leave a Reply

Your email address will not be published. Required fields are marked *

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .