The dpkg command in Linux: package management. deb

Introduction

In the Debian-based distribution ecosystem, .deb package management is a daily task for managers and advanced users. Although tools like APT or aptitude simplify unit resolution, understand the commanddpkgallows you to work directly with the package files and solve situations where high-level managers fail.

What is dpkg?

dpkg is the Debian system's low-level package manager. Its main function is to install, delete, update and consult .deb packages, but does not automatically solve dependencies. Each operation carried out dpkg is recorded in the database located in/ var / lib / dpkg, which allows 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 the need for repositories, which is useful to test custom versions or recover damaged packages. On the other hand, its main limitation is the absence of unit resolution: if you try to install a package that requires absent libraries, dpkg will fail and leave the package in conditionunpackedorhalf‑configured, requiring manual intervention.

Basic Command

  • Install a package: sudo dpkg -i paquete_nombre.deb
  • Remove a package: sudo dpkg -r nombre_paquete(removes by leaving configuration files) orsudo dpkg -P nombre_paquete(full purging).
  • Consult status: dpkg -l | grep nombreshows if it is installed, its version and description.
  • Reconfigure a package: sudo dpkg-reconfigure nombre_paqueteuseful after changing configuration options.
  • Show detailed information: dpkg -s nombre_paqueteindicates version, architecture, dependencies and status.
  • List files from a package: dpkg -L nombre_paquetedisplays all the 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 units, you can complete the installation with:

sudo apt-get install -f

This command invokes APT to satisfy the outstanding dependencies.

To remove an application you no longer need and also delete your 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

Good practices and troubleshooting

  • Always check the dpkg log in/ var / log / dpkg.logwhen an installation fails; there you will find detailed error messages.
  • Before installing an unknown .deb package, check your signature or control sum to avoid security risks.
  • If a package is in placehalf‑installed, runsudo dpkg --configure -ato try to complete the pending configuration.
  • Useapt-mark holdto prevent automatic updates from replacing a version you have manually installed with dpkg.
  • In server environments, it combines dpkg with automation scripts that verify the return code ($?) and act according to the result.

Conclusion

Although high-level tools like APT are the most comfortable option for day-to-day package management, dpkg remains the underlying pillar that provides accurate control over each .deb. file. Dominating your commands and understanding your limitations allows you to install, depurate and recover packages in scenarios where automated managers are not enough, becoming a more versatile and secure Linux manager.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish