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.
| Task | dpkg command | rpm command |
|---|---|---|
| List all installed packages | dpkg -l | rpm -qa |
| Find package owning a file | dpkg -S | rpm -qf |
| Show package info | dpkg -s | rpm -qi |
| List files in a package | dpkg -L | rpm -ql |
| Verify package integrity | debsums | rpm -V |
| Remove a package | apt remove / dpkg -r | dnf 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 -lrpm -qaThe output of dpkg -l can be long, so filter it with grep when you're looking for a specific package.
dpkg -l | grep -i nginxFor rpm, sort the list alphabetically for easier scanning.
rpm -qa | sort | grep -i nginxCount 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 -lThe 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/nginxrpm -qf /usr/sbin/nginxIf 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 python3Check 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 nginxrpm -qi nginxTo see what a package depends on without installing it, query the repository metadata instead of the installed database.
apt-cache depends nginxdnf repoquery --requires nginxTo see which packages depend on a given package, the reverse lookup helps before you remove something shared.
apt-cache rdepends libssl3dnf repoquery --whatrequires openssl-libsList 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 nginxrpm -ql nginxThis 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 debsumsdebsums nginxOn 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 nginxAn 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.
| Code | Meaning |
|---|---|
| S | File size differs |
| M | Permissions or file type differs |
| 5 | MD5 checksum differs (content changed) |
| U | Owner differs |
| G | Group differs |
| T | Modification time differs |
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-runsudo dnf repoquery --unneededThe 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 autoremovesudo dnf autoremoveTo 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 -yVerify your setup
dpkg -l | wc -l
rpm -qa | wc -l
sudo apt list --installed 2>/dev/null | wc -l
sudo dnf list installed | wc -lConfirm a specific package and its files resolve correctly.
dpkg -s nginx | grep Status
rpm -qi nginx | grep VersionCommon issues
| Symptom | Cause | Fix |
|---|---|---|
| dpkg -l shows package as rc | Package removed but config files remain | Purge 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 rpm | Expected behavior, check the application's own documentation instead |
| debsums command not found | Package not installed by default on Ubuntu/Debian | sudo apt install -y debsums |
| rpm -V reports changes on config files | You intentionally edited the config | Safe to ignore for files marked with a c flag |
| autoremove wants to remove a package you still need | Package was marked as automatically installed by mistake | sudo apt-mark manual package-name before running autoremove |
| dpkg database locked error | Another package manager process is running | Wait for it to finish or check with sudo lsof /var/lib/dpkg/lock |
Next steps
- Configure Linux package management with apt, dnf and yum for system updates
- Fix apt update E: Repository no longer has a Release file
- Check Linux system information with uname, hostnamectl and neofetch
- Configure automatic security updates with unattended-upgrades and email notifications
- Audit installed software and generate package inventory reports