Check and manage installed packages with dpkg and rpm on Linux

Beginner 15 min Dec 03, 2026
Ubuntu 24.04 Ubuntu 22.04 Debian 12 Debian 11 AlmaLinux 9 Rocky Linux 9 Fedora 41

Learn how to list installed packages, find which package owns a file, inspect versions and dependencies, verify package integrity, and safely remove orphaned packages using dpkg on Debian/Ubuntu and rpm on RHEL-based distros.

Prerequisites

  • A Linux server running Ubuntu, Debian, AlmaLinux, Rocky Linux or Fedora
  • sudo or root access
  • Basic familiarity with the terminal

What this solves

Every Linux distribution tracks installed software through a package database. Debian and Ubuntu use dpkg, while AlmaLinux, Rocky Linux and Fedora use rpm. This tutorial shows you how to list installed packages, find which package owns a specific file, check versions and dependencies, verify package integrity, and clean up orphaned packages on both families.

These are everyday troubleshooting skills: you'll use them when debugging missing binaries, auditing what's on a server, or cleaning up after removing software.

Step-by-step configuration

Understand dpkg vs rpm

dpkg is the low-level package manager for Debian-based systems (Ubuntu, Debian). rpm is the equivalent for Red Hat-based systems (AlmaLinux, Rocky Linux, Fedora). Both manage individual package files, dependency metadata and installed file lists, but they don't resolve dependencies or fetch packages from repositories on their own.

apt and dnf sit on top of dpkg and rpm respectively, handling repository access and dependency resolution. If you're also managing updates, see configure Linux package management with apt, dnf and yum.

Taskdpkg commandrpm command
List all installed packagesdpkg -lrpm -qa
Find package owning a filedpkg -Srpm -qf
Show package infodpkg -srpm -qi
List files in a packagedpkg -Lrpm -ql
Verify package integritydebsumsrpm -V
Remove a packageapt remove / dpkg -rdnf remove / rpm -e

List all installed packages

dpkg -l shows every package tracked by the dpkg database, with status flags, name, version and a short description. rpm -qa lists just the package names and versions, one per line.

dpkg -l
rpm -qa

The output of dpkg -l can be long, so filter it with grep when you're looking for a specific package.

dpkg -l | grep -i nginx

For rpm, sort the list alphabetically for easier scanning.

rpm -qa | sort | grep -i nginx
Note: On rpm systems, rpm -qa --last shows packages sorted by install date, which is useful for figuring out what was recently added to a server.

Count and summarize installed packages

To get a quick count of installed packages, pipe the listing through wc -l.

dpkg -l | grep -c '^ii'
rpm -qa | wc -l

The ii prefix in dpkg -l output means the package is fully installed and configured. Other common flags are rc (removed, config files remain) and un (unknown/not installed).

Find which package owns a specific file

This is one of the most useful package queries. If a binary or config file exists but you don't know what installed it, dpkg -S or rpm -qf will tell you.

dpkg -S /usr/sbin/nginx
rpm -qf /usr/sbin/nginx

If the file belongs to a package you haven't installed directly, dpkg -S also works on files that were never shipped by apt, as long as they're tracked in the dpkg database. For files not yet indexed (just downloaded, not from a package), use which first to resolve the full path.

which python3
Warning: dpkg -S and rpm -qf only work on files that are part of an installed package. Files created by applications at runtime (logs, uploads, cache) will not show up, and that's expected behavior, not a bug.

Check package details, version and dependencies

Use dpkg -s or rpm -qi to see a package's version, maintainer, install size, and dependency list.

dpkg -s nginx
rpm -qi nginx

To see what a package depends on without installing it, query the repository metadata instead of the installed database.

apt-cache depends nginx
dnf repoquery --requires nginx

To see which packages depend on a given package, the reverse lookup helps before you remove something shared.

apt-cache rdepends libssl3
dnf repoquery --whatrequires openssl-libs

List all files installed by a package

When you need to see every file a package placed on disk, use dpkg -L or rpm -ql.

dpkg -L nginx
rpm -ql nginx

This is handy for finding the main config file of a package you've never touched before, or confirming whether a systemd unit file was actually shipped by the package.

Verify package integrity

Verification compares the current state of installed files against the checksums recorded at install time. This detects accidental edits, corruption, or tampering.

On Debian and Ubuntu, install debsums, which is not included by default.

sudo apt install -y debsums
debsums nginx

On rpm-based systems, verification is built in via rpm -V. It checks file size, permissions, owner, group, and checksum, and prints a code for each discrepancy.

rpm -V nginx

An empty output means everything matches. If you see a line, the first character codes map to specific checks: S for size, M for mode/permissions, 5 for checksum mismatch, and T for modification time.

CodeMeaning
SFile size differs
MPermissions or file type differs
5MD5 checksum differs (content changed)
UOwner differs
GGroup differs
TModification time differs
Note: Config files (marked with a c in rpm -V output) are expected to change after you edit them, so a 5 code on a config file you intentionally modified is normal, not a security problem.

Remove orphaned packages safely

Orphaned packages are dependencies that were pulled in automatically but are no longer required by anything you installed directly. Leaving them around wastes disk space and widens your patching surface unnecessarily.

sudo apt autoremove --dry-run
sudo dnf repoquery --unneeded

The dry-run and repoquery commands only show what would be removed. Review the list before actually removing anything, especially on a production server.

sudo apt autoremove
sudo dnf autoremove

To remove leftover configuration files from packages that were already removed but not purged, use apt purge on Debian/Ubuntu.

dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo apt purge -y
Warning: Never run autoremove or purge commands blindly on a production system without reviewing the package list first. Some packages flagged as orphaned may still be required by custom scripts or cron jobs that aren't tracked by the package manager.

Verify your setup

dpkg -l | wc -l
rpm -qa | wc -l
sudo apt list --installed 2>/dev/null | wc -l
sudo dnf list installed | wc -l

Confirm a specific package and its files resolve correctly.

dpkg -s nginx | grep Status
rpm -qi nginx | grep Version

Common issues

SymptomCauseFix
dpkg -l shows package as rcPackage removed but config files remainPurge it with sudo apt purge package-name
rpm -qf reports "file not owned by any package"File was created manually or by an app, not by rpmExpected behavior, check the application's own documentation instead
debsums command not foundPackage not installed by default on Ubuntu/Debiansudo apt install -y debsums
rpm -V reports changes on config filesYou intentionally edited the configSafe to ignore for files marked with a c flag
autoremove wants to remove a package you still needPackage was marked as automatically installed by mistakesudo apt-mark manual package-name before running autoremove
dpkg database locked errorAnother package manager process is runningWait for it to finish or check with sudo lsof /var/lib/dpkg/lock

Next steps

Running this in production?

Want this handled for you? This works for a single server. When you run multiple environments or need consistent package auditing, patch tracking and dependency hygiene across a fleet, keeping it healthy is a different job. See how we run infrastructure like this for European teams.
#dpkg #rpm #package management #linux administration #apt #dnf #debian #rhel

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. Fully managed, with one fixed contact who knows your setup.

You get one fixed contact who knows your setup

At their desk in Rotterdam 15:18 · reachable in a message, no ticket form

Learn more: managed cloud infrastructure