APT and dpkg
Quick answer
On Debian and Ubuntu, APT coordinates dependency resolution and package acquisition; dpkg manages local Debian packages and their installed state. Use queries and simulation before a real transaction.
Prepare the practice environment
Use an ordinary user in a disposable VM of the distribution named in the example. For Debian examples use python3 lab-fixtures/packages/setup.py from the extracted package root, enter the printed directory and check pwd; alternatively create a private directory with mktemp -d. Use a fresh directory per example, export LC_ALL=C and Bash with set -o pipefail. Do not use sudo. Keep -s and --no-download on every APT simulation. Skip missing tools; do not install them merely to run an example. On Alpine the simple query also works in a compatible sh. Outputs vary by installed versions and repository state. Stop on unexpected failure.
How it works
apt update refreshes repository indexes; it does not upgrade installed packages. apt upgrade upgrades packages subject to its rules; apt full-upgrade may remove packages to resolve dependencies. apt install NAME installs a package and dependencies. dpkg -i FILE.deb installs a local archive without fetching missing dependencies; it can leave an incomplete configuration. Prefer apt install ./FILE.deb for a trusted local archive in a VM. apt is interactive-oriented; use stable documented interfaces like dpkg-query for automation. Real updates, installation and removal require authorization and a disposable VM snapshot; no state-changing commands are needed here.
A package ownership query searches recorded paths, not the contents of the executable. A symlink or a merged-/usr layout can explain why the path returned by command lookup differs from the recorded path. A successful simulation can include planned upgrades or removals even when no new packages are proposed. Check the simulation exit status and the entire transaction summary, including the upgraded and removed counts; the single message in the example proves only that the new-package count is zero. Do not infer that no changes are planned from that message alone.
Try the examples
On the tested merged-/usr Debian system this path is recorded by bash. Other releases may record /bin/bash; query both if needed.
Expected stdout:
bash: /usr/bin/bashThis reads the dpkg record. It does not prove every file remains intact.
Expected stdout:
Status: install ok installedapt-get -s --no-download install bash > plan.txtgrep -q '0 newly installed' plan.txt && printf 'no new packages planned\n'In the tested cached state Bash was already installed and no changes were planned. On other systems inspect plan.txt directly: simulation can propose installs, upgrades or removals; it is not a guarantee of later results. The redirect writes only a new fixture file.
Expected stdout:
no new packages plannedCommon mistakes
Do not confuse apt update with apt upgrade. Do not remove package-managed files manually to fix dependency errors; inspect the transaction and diagnose the package database.
Practice
In a Debian VM inspect the owner of the executable returned by command -v bash. Simulate an install with -s --no-download, then identify the proposed actions without applying them.
Related references
Study: apt, apt-get, apt-cache, dpkg, dpkg-query. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
APT and dpkg — Knowledge Check
Apply package-management concepts to the stated distribution and query-only lab.
What does apt update change?
Which command finds the owning installed package?
What does apt-get -s do?
Why can dpkg -i leave a package unconfigured?