Skip to content
Intermediate LinuxLesson 12 of 27 2 min read

Package Management

Install, remove, and search for software with apt.

On this page5 sections

Every Linux distribution ships a package manager: a tool that installs software along with everything it depends on, tracks exactly which files belong to which program, and can cleanly remove it all again later. This is the single biggest reason Linux servers rarely end up with the tangled, half-installed software that plagues systems without one.

apt: Debian and Ubuntu's package manager

apt is the tool you will meet on Debian, Ubuntu, and their many derivatives.

bash
apt update                # refresh the local index of what's available
apt install tree          # install a package (and its dependencies)
apt remove tree           # remove it again
apt search editor         # search the index for a term
apt list --installed      # show everything currently installed

apt update does not install or upgrade anything by itself - it just refreshes apt's knowledge of what versions are available from your configured repositories. Get in the habit of running it before an install, so you are not installing a version that's already out of date.

dpkg: what apt is built on

Underneath apt is dpkg, the lower-level tool that actually unpacks .deb files and records which files belong to which package (traditionally under /var/lib/dpkg). You will rarely need it directly, but it explains why apt can tell you precisely what is installed: it is reading that same bookkeeping.

Other distributions, other tools

The concept is universal even though the command names differ:

Distribution familyPackage manager
Debian, Ubuntu, Mintapt (built on dpkg)
Fedora, RHEL, CentOSdnf (formerly yum, built on rpm)
Arch Linux, Manjaropacman

Once you understand one of them - update the index, install a name, remove a name, search a term - the others are just a different vocabulary for the same four ideas.

Try it

Run these in the practice terminal (opens in a new tab). It opens in a new tab, so you keep your place here.
bash
apt update
apt search git
apt install git
apt list --installed
apt remove git

Further reading

  • "The Linux Command Line" by William Shotts (No Starch Press) - its package management chapter covers both the Debian (apt/dpkg) and Red Hat (dnf/rpm) families in detail.
  • "How Linux Works" by Brian Ward (No Starch Press) - explains what a package actually contains and how dependency resolution works under the hood.
  • "UNIX and Linux System Administration Handbook" by Nemeth, Snyder, Hein, Whaley, and Mackin (Pearson) - covers package management as part of real production server administration, including keeping systems patched and up to date.

Challenge

Install the tree package with apt, in a single command that also refreshes the package index first.

Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.

Quiz

Lock in the concepts. Score at least 80% to mark the lesson complete.

0 of 2 answered

Done with this one?

Skipped the challenge? You can mark the lesson complete by hand.

Your notes

Kept on this browser only.