The apt command in Linux
apt is the package manager front-end on Debian and Ubuntu: it resolves dependencies, fetches signed packages from repositories and keeps the system upgradable in one command. The concepts transfer directly to dnf (Fedora/RHEL) and pacman (Arch) — same ideas, different spellings. Two-step rhythm to internalize: update the index, then act.
How apt works
apt is the strategist over dpkg's mechanics. Repositories publish signed indexes; apt update downloads them into /var/lib/apt/lists — a local catalog of every available version. Install requests run the dependency solver over that catalog, producing a plan (install these, upgrade those) that dpkg then executes package by package. update refreshes knowledge; everything else acts on it — hence the eternal pairing.
Trust is cryptographic end to end: each repository's Release file is GPG-signed, and indexes carry hashes of every package, so a tampered mirror fails verification rather than installing quietly. Meanwhile dpkg tracks which config files under /etc belong to which package and whether you edited them — the machinery behind those "config file modified" prompts during upgrades, and behind purge knowing exactly what to remove.
Syntax
apt COMMAND [PACKAGE] Common options
| Option | What it does |
|---|---|
update | Refresh the package index (what versions exist). Changes nothing installed. |
upgrade | Install available upgrades for everything. |
install PKG | Install (or upgrade) a package with its dependencies. |
remove / purge PKG | Uninstall / uninstall including config files. |
search TERM | Find packages by name/description. |
show PKG | Details: version, size, dependencies, description. |
autoremove | Delete dependencies nothing needs anymore. |
How to use apt: examples
$ sudo apt update && sudo apt upgrade The maintenance pair: refresh the index, apply upgrades.
$ sudo apt install htop ripgrep Install several packages at once.
$ apt search json | grep -i cli Hunt for a tool by keyword.
$ apt show nginx Inspect before installing.
$ sudo apt purge oldapp && sudo apt autoremove Clean removal including config and orphaned dependencies.
Real-world use cases for apt
The patching routine
apt update && apt list --upgradable to see what's pending, apt upgrade to apply, checking whether kernel or libc moved (reboot territory). Boring, reviewable, and the single highest-leverage security habit a server owner has.
Tracing a file to its owner
A mystery config appears: dpkg -S /etc/thing.conf names the package it belongs to; apt show explains it; dpkg -L lists everything else it installed. The package database as a map of the whole system.
Pro tips and common mistakes
- apt update changes nothing installed — run it freely; it is the catalog refresh, not the upgrade.
- Prefer purge + autoremove for clean removals; remove alone strands config files and orphans dependencies.
- On Fedora/Arch the verbs translate (dnf, pacman -Syu) but the concepts — index, solver, signatures — are identical.
Frequently asked questions about apt
update vs upgrade?
update downloads the catalog; upgrade installs from it. Running upgrade without a recent update upgrades against stale information — hence the eternal pairing.
"Unable to locate package"?
Index stale (run apt update), name misspelled (apt search it), or the package lives in a repository you have not enabled.
And on Fedora or Arch?
Same grammar: dnf install / dnf upgrade; pacman -S pkg / pacman -Syu. Learn the concepts once, translate the verbs.
Related commands
Download files, test APIs, send POST requests with JSON, and inspect headers.
sudo & suTemporary privilege, audited — and why sudo won everywhere.
which & typeWhich binary actually runs when you type a name — and unmask aliases.