Debian/Ubuntu package management: apt and dpkg
The .deb format, apt as the modern front-end, and dpkg underneath it. · 9 min
Debian and Ubuntu use the `.deb` package format. `dpkg` is the low-level tool that actually installs, removes, and queries individual `.deb` files, but it does not resolve dependencies or download anything — if a package needs another package that isn't installed, `dpkg` will simply fail. `apt` (and the closely related `apt-get`) is the higher-level tool almost everyone uses day-to-day: it talks to configured repositories, resolves and installs dependencies automatically, and manages the whole lifecycle of installing, updating, and removing software.
The standard workflow: `sudo apt update` refreshes the local list of available packages and their versions from configured repositories (this does not install or upgrade anything by itself — it's purely a metadata refresh, a distinction that surprises people expecting it to update software). `sudo apt upgrade` then actually upgrades installed packages to their latest available versions. `sudo apt install <package>` installs a new package plus its dependencies. `sudo apt remove <package>` uninstalls it but leaves configuration files behind (for a clean full removal including config, use `apt purge`).
Repositories are defined in `/etc/apt/sources.list` and `/etc/apt/sources.list.d/` — these tell `apt` where to fetch package metadata and files from. Adding a third-party repository (a PPA on Ubuntu, or a vendor-provided `.list` file) extends what `apt install` can find beyond the distribution's own default package set, but also means trusting that repository's maintainers and signing key.
| Command | Purpose | Example |
|---|---|---|
| apt update | Refresh the local package index from configured repositories (metadata only, installs nothing) | — |
| apt upgrade | Upgrade all installed packages to their latest available version | — |
| apt install | Install a package and its dependencies | sudo apt install nginx |
| apt remove / purge | Uninstall a package; purge also removes its configuration files | sudo apt purge nginx |
| apt search | Search available packages by name/description | apt search postgresql |
| dpkg -l | List all currently installed packages (low-level) | — |
| dpkg -i file.deb | Install a standalone .deb file directly (no dependency resolution) | — |
Common Mistakes
- ⚠ Forgetting `sudo apt update` before `apt install` on a fresh system and getting a "package not found" error for a package that genuinely exists in the repositories
- ⚠ Confusing `apt update` (refresh metadata) with `apt upgrade` (actually upgrade software) — they do very different things despite similar names
- ⚠ Using `apt remove` and expecting configuration files to be gone too — that requires `purge`
Takeaway: `apt update` only refreshes what apt knows is available; it never installs or upgrades anything by itself — that surprises almost everyone exactly once before it becomes second nature.