Package Management
apt/dpkg, yum/dnf/rpm, snap, and compiling from source — the full software installation stack.
Overview
Package managers are the first skill you use on any new server. Knowing both ecosystems is essential because job requirements don't pick one family for you.
Two Major Families
- Debian / Ubuntu — apt — dpkg — .deb
- RHEL / Fedora / CentOS — dnf / yum — rpm — .rpm
Critical Rule
Always apt update before apt install — without it you install from a stale package list and may get old versions or 'not found' errors.
Never curl https://... | bash in production. Review the script first. Download it, read it, then run it.
Daily Commands (Debian/Ubuntu)
Daily Commands (RHEL/Fedora)
Linux package management splits into two major ecosystems: Debian-based (apt/dpkg) and RHEL-based (yum/dnf/rpm). Understanding both is essential for working across distributions.
Debian ecosystem (Ubuntu/Debian): apt is the high-level tool that handles dependency resolution and downloads from repositories. dpkg is the low-level backend that actually installs .deb files. apt update refreshes the package index from sources. apt upgrade installs newer versions of currently installed packages. apt dist-upgrade additionally resolves dependency changes (may add or remove packages). apt full-upgrade is the modern equivalent of dist-upgrade. Repositories are defined in /etc/apt/sources.list and files under /etc/apt/sources.list.d/.
RHEL ecosystem (CentOS/Fedora/RHEL): dnf (Dandified YUM) replaced yum in Fedora 22+ and RHEL 8+. dnf is faster with better dependency resolution and memory usage. rpm is the low-level tool. rpm -qa queries all installed packages, rpm -qi package shows info, rpm -ql package lists files, rpm -qf /path/to/file identifies which package owns a file.
Finding package ownership: On Debian: dpkg -S /path/to/file. On RHEL: rpm -qf /path/to/file.
snap: Canonical's universal package format — self-contained with dependencies bundled. Confinement levels: strict (sandboxed), classic (full system access like traditional packages), devmode (for development). snap list shows installed snaps.
Compiling from source: ./configure --prefix=/usr/local checks dependencies and generates Makefile, make compiles, sudo make install installs. Use checkinstall instead of make install to create a proper package for later removal.
Key concepts
- apt vs dpkg
- apt is the high-level frontend (handles dependencies, downloads). dpkg is the low-level backend (installs .deb files directly). apt uses dpkg under the hood.
- dnf vs rpm
- dnf (next-gen yum) handles dependency resolution and repo downloads. rpm operates on local .rpm files. dnf install package vs rpm -ivh package.rpm.
- /etc/apt/sources.list format
- deb http://archive.ubuntu.com/ubuntu focal main restricted universe — fields: type, URL, suite (codename), components. deb-src for source packages.
- snap confinement levels
- strict: sandboxed, limited system access. classic: full system access like traditional packages. devmode: debugging, all access, logs warnings.
When to use it
- Installing or removing software on Linux servers
- Auditing installed packages for security vulnerabilities
- Setting up reproducible server environments
- Troubleshooting missing library errors
Interview questions
- What is the difference between apt update, apt upgrade, and apt dist-upgrade?
- How would you find which package owns a specific file on a Debian/Ubuntu system?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio