Manage Debian packages directly with dpkg: query
status, list installed packages, enumerate files owned by a
package, and identify file ownership. Install a local
.deb, recover cleanly with APT when dependencies
break, then remove and purge to understand the full lifecycle.
You are working on a Debian-based system where package work
needs to be done at the dpkg level. You must verify package
state, determine which package owns a given file, and install
a local .deb artifact. When the install leaves
the package unconfigured due to dependency issues, you will
use APT to correct the system, then remove and fully purge the
package.
dpkg installs packages but does not resolve
dependencies. In real ops, you often pair dpkg with APT to
complete the transaction and return the system to a
consistent state.
dpkg -s.
dpkg -l.
dpkg -L.
dpkg -S.
.deb using dpkg -i.
apt-get -f install.
dpkg -r.
dpkg -P.
dpkg is the low-level package tool for the
local package database and .deb files.
dpkg does not fetch dependencies. APT is the
dependency resolver and installer frontend.
bash package.
dpkg -s bash
dpkg -s queries the dpkg database for a package
and reports its status. This is how you confirm whether a
package is installed and in a healthy configured state.
Package: bash
Status: install ok installed
Priority: required
Version: 5.1-2ubuntu3
dpkg -l | head -n 10
dpkg -l lists packages known to dpkg and their
desired/actual state. This is useful for quick audits and
confirming whether a package is installed, removed, or
purged.
Desired=Unknown/Install/Remove/Purge/Hold
||/ Name Version Architecture Description
ii adduser 3.118 all add and remove users and groups
ii apt 2.4.5 amd64 commandline package manager
ii base-files 12ubuntu4 amd64 Debian base system miscellaneous files
ii bash 5.1-2ubuntu3 amd64 GNU Bourne Again SHell
bash package.
dpkg -L bash | head -n 20
dpkg -L enumerates paths installed by a package.
Use this to locate binaries, docs, and man pages and to
confirm exactly what a package put on disk.
/.
/bin/bash
/usr/share/doc/bash/README.gz
/usr/share/man/man1/bash.1.gz
/bin/bash.
dpkg -S /bin/bash
dpkg -S maps a file path back to the owning
package. This is foundational for troubleshooting and for
answering “where did this file come from?”
bash: /bin/bash
.deb file with dpkg.
This step demonstrates a common dpkg outcome: the package is unpacked, but configuration fails because dependencies are missing. That is expected when you bypass APT.
sudo dpkg -i htop_3.0.5-1_amd64.deb
dpkg -i installs a local package file but does
not fetch dependencies. If dependencies are missing, dpkg
leaves the package unconfigured until the system is fixed.
Selecting previously unselected package htop.
(Reading database ... 123456 files and directories currently installed.)
Preparing to unpack htop_3.0.5-1_amd64.deb ...
Unpacking htop (3.0.5-1) ...
dpkg: dependency problems prevent configuration of htop:
htop depends on libc6 (>= 2.34); however:
Package libc6 is not configured yet.
dpkg: error processing package htop (--install):
dependency problems - leaving unconfigured
sudo apt-get -f install
This repairs broken installs by resolving dependencies and completing configuration. This is the standard recovery path when dpkg leaves packages unconfigured.
Reading package lists... Done
Building dependency tree... Done
Correcting dependencies... Done
The following additional packages will be installed:
libc6
Setting up libc6 ...
Setting up htop (3.0.5-1) ...
htop is now configured (or removed if APT chose that path).
dpkg -s htop | egrep '^(Package|Status|Version)'
After a fix install, verify the package status. You want to see an “install ok installed” style state for a clean install.
Package: htop
Status: install ok installed
Version: 3.0.5-1
sudo dpkg -r htop
dpkg -r removes the package but preserves
configuration files. This is useful when you might reinstall
later and want prior settings retained.
(Reading database ... 123460 files and directories currently installed.)
Removing htop (3.0.5-1) ...
Processing triggers for man-db ...
sudo dpkg -P htop
dpkg -P purges configuration files and removes
package traces. Use this for a clean removal when config
should not persist.
(Reading database ... 123450 files and directories currently installed.)
Purging configuration files for htop (3.0.5-1) ...
If dpkg is not found, you are likely on an RPM-based
distro. Use the equivalent tooling (rpm, dnf)
or run this lab inside a Debian/Ubuntu VM/container.
This lab assumes the htop_3.0.5-1_amd64.deb file is
already present in your working directory. In real ops, you
confirm the artifact path before running dpkg -i.
APT may choose removal if it cannot resolve dependencies cleanly. If that happens, treat it as the outcome and verify the dpkg status, then proceed with remove/purge steps as needed.
Your goal is to leave the system in a clean state with no leftover dpkg locks and no partially installed packages.
dpkg -l | grep -E '^(iU|iF|iH|rc)' || true
dpkg -s htop 2>/dev/null | egrep '^(Package|Status|Version)' || true
No “half-installed/unconfigured” packages remain, and the example package is either fully installed and configured or fully removed/purged as intended.
dpkg -s <pkg>
: Show package status and metadata.
dpkg -l
: List packages and their state (installed/removed/purged).
dpkg -L <pkg>
: List files installed by a package.
dpkg -S <path>
: Identify which installed package owns a path.
dpkg -i <file.deb>
: Install a local .deb (no dependency resolution).
apt-get -f install
: Fix broken installs by resolving dependencies and completing configuration.
dpkg -r <pkg>
: Remove a package but keep configuration files.
dpkg -P <pkg>
: Purge a package including configuration files.