The Three Layers

Chapter 2
APT in Depth
apt vs apt-get vs dpkg — three layered tools, and the everyday commands for installing, removing, and upgrading on Debian/Raspbian

This is the chapter most directly relevant to Philip's own machines — Debian on the server, Raspberry Pi OS (Raspbian) on the Pi. Three different tools all do package management on these systems, and understanding how they relate avoids real confusion about which one to actually reach for.

The Three Layers

apt — the modern, friendly front end apt-get / apt-cache — the older, scriptable tools dpkg — the low-level engine underneath both
Each layer calls down into the one below it — apt and apt-get both ultimately use dpkg to actually install files
apt
Introduced specifically to give a cleaner, more consistent command set for everyday interactive use — a progress bar, colour output, and sensible defaults. The right default choice for almost everything in this chapter.
apt-get / apt-cache
The original tools, still fully functional and more commonly seen in older scripts and documentation — slightly more stable output formatting, which is why scripts sometimes still prefer apt-get over apt deliberately.
dpkg
Works directly with individual .deb files and the local package database — no repository awareness, no dependency resolution of its own. Genuinely useful for specific low-level tasks, covered in Chapter 4.
For interactive, everyday use, just use apt — for scripts, apt-get's output is considered more stable
The apt manual page itself notes that apt's command-line interface is allowed to change between versions in ways that could break a script depending on exact output formatting — apt-get's interface is guaranteed stable, which is why automated scripts conventionally still use apt-get even though apt is the better choice for a human typing commands directly.

Everyday Commands

$ # Refresh the local list of available packages and versions from configured repos
$ sudo apt update

$ # Install a package (resolves and installs dependencies automatically)
$ sudo apt install nginx

$ # Remove a package, keeping its configuration files
$ sudo apt remove nginx

$ # Remove a package AND its configuration files
$ sudo apt purge nginx

$ # Upgrade every installed package to its latest available version
$ sudo apt upgrade

$ # Search for a package by name or description
$ apt search "web server"

$ # Show detailed information about a package before installing
$ apt show nginx
apt update does NOT install anything — it's commonly confused with upgrade
apt update only refreshes the local cache of what's available in the configured repositories — it changes nothing about what's actually installed on the system. apt upgrade is the command that actually applies new versions. The conventional, near-universal pairing is sudo apt update && sudo apt upgrade — update first so upgrade has current information to work from.

remove vs purge — A Distinction Worth Understanding

  • apt remove — uninstalls the software itself, but deliberately leaves configuration files behind (typically in /etc/) — useful if you might reinstall later and want your settings preserved.
  • apt purge — removes the software AND every configuration file associated with it — the genuinely complete uninstall, for when you're certain you won't need the package or its settings again.

autoremove — Cleaning Up Orphaned Dependencies

$ sudo apt autoremove
The following packages will be REMOVED:
libold-dependency1

When a package is removed, any dependency that was installed automatically just for it — and isn't needed by anything else still installed — becomes an "orphan." autoremove identifies and cleans these up, preventing a slow accumulation of unused packages over months of installing and removing software.

Full vs Minimal Upgrades

CommandWhat it does
apt upgradeUpgrades packages, but won't remove an existing package to satisfy a new dependency requirement
apt full-upgradeWill remove packages if genuinely necessary to complete an upgrade — used for major version transitions
apt dist-upgradeThe older name for full-upgrade — same behaviour, still widely seen in documentation

Chapter 2 Quick Reference

  • apt — the modern, friendly default for everyday interactive use
  • apt-get — older, output-stable, conventionally still preferred in scripts
  • dpkg — the low-level engine both call into; works with individual .deb files directly
  • apt update — refreshes the package list only, installs/changes nothing; always pair with upgrade
  • apt install/remove/purge/upgrade — the core everyday verbs
  • remove vs purge: remove keeps config files; purge removes everything, including config
  • apt autoremove — cleans up orphaned dependencies left behind by removed packages
  • apt full-upgrade/dist-upgrade — will remove packages if necessary; plain upgrade never will
  • Next chapter: managing repositories on Debian-based systems — sources.list, third-party repos, apt keys