Packages and backups

The dpkg command

Installs, removes and queries .deb packages on Debian and its derivatives, at a low level. It does not resolve dependencies or download anything: that is apt's job. It is the tool apt uses underneath for every installation.

Syntax

dpkg [opciones] acción [paquete|archivo]Try it in the terminal →

Most useful options

-i <archivo.deb>Installs a downloaded package. If dependencies are missing, finish with apt -f install.
-r <paquete>Removes the package but keeps its configuration files.
-PAlso removes the configuration. This is the option for a complete removal.
-l [patrón]Lists the installed packages, with their status and version.
-L <paquete>Shows the files the package installed.
-S <ruta>Tells which package installed a given file.
-s <paquete>Shows the status, version and description of a package.
--auditChecks for half-installed packages and suggests fixes.
--configure -aFinishes pending configurations after an interrupted run.

Copy-ready examples

$ dpkg -l | grep nginxLooks for nginx among the installed packages. The first column is the status: ii means installed.

Example output

ii  nginx        1.22.1-9  amd64  small, powerful, scalable web/proxy server
ii  nginx-common 1.22.1-9  all    small, powerful, scalable web/proxy server - common files
$ dpkg -S /usr/bin/curlWhich package installed that file.

Example output

curl: /usr/bin/curl
$ sudo dpkg -i descargas/app_2.1_amd64.debInstalls a local .deb. If it asks for dependencies, continue with sudo apt -f install.
$ dpkg -L curl | head -3First paths that curl installed.

Example output

/.
/usr
/usr/bin
$ sudo dpkg --configure -aFinishes configuring packages left half-done.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
dpkg: error: requested operation requires superuser privilegeInstalling or removing packages requires root.Run the same command again with sudo in front.
dpkg-query: package 'nopkg' is not installed and no information is availableThe package is not installed or the name is misspelled.Find the exact name with dpkg -l | grep text or apt search text.
dpkg: error: cannot access archive 'app.deb': No such file or directoryThe path to the .deb is misspelled or the file is not in that folder.List the folder with ls and use the full path.

Typical mistakes

  • If dpkg -i fails on dependencies, the system is left half-configured: run sudo apt -f install.

Differences from similar commands

  • apt: Resolves dependencies, downloads from repositories and installs, upgrades or removes. dpkg only works with files already on disk.
  • apt-cache: Searches and shows information from the repositories, without installing anything.

Security

Installing a .deb with dpkg -i runs its scripts as root without anyone reviewing them. Install only packages from official repositories or signed sources, and check the hash of the downloaded file. Also check where each .deb came from before installing it.

Related commands

FAQ

How do I see which version is installed?

With dpkg -s name, on the Version line. dpkg-query -W name also works and prints a single line. Both work without root.

What does 'rc' mean in the list?

The package was removed but keeps its configuration. Purge it with dpkg -P name.

Can I install a .deb built for another distribution?

Better not: its dependencies often break the system. Look for a package built for your distribution.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course