Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 37 ยท Packages and Services

Package Managers: apt, dnf and rpm Explained

Install, update, query and remove software with apt and dpkg on Debian systems and dnf and rpm on Red Hat systems, including dependency handling and package queries.

A package is an archive holding programs, configuration files and metadata such as its version and dependencies. A package manager downloads packages from trusted repositories, installs their dependencies, records what it installed and can remove or upgrade it cleanly. Using it instead of copying files by hand makes a system reproducible and auditable.

There are two layers. Low-level tools (dpkg, rpm) handle single package files. High-level tools (apt, dnf) talk to repositories and solve dependencies.

Debian family: apt and dpkg

Terminal
sudo apt update                    # refresh package lists
sudo apt upgrade                   # upgrade installed packages
sudo apt full-upgrade              # also add/remove packages as needed
sudo apt install nginx             # install
sudo apt install nginx=1.24.0-1    # specific version (name from apt policy)
sudo apt remove nginx              # remove program, keep config
sudo apt purge nginx               # remove program and config
sudo apt autoremove                # drop unneeded dependencies
apt search "web server"
apt show nginx
apt list --installed | grep ssl

apt update only downloads indexes; it does not install anything. Run it before installing so you see current versions.

Low-level queries:

Terminal
dpkg -l | grep nginx        # installed packages
dpkg -L nginx               # files in a package
dpkg -S /usr/sbin/nginx     # which package owns this file
sudo dpkg -i package.deb    # install a local file (no dependency fetching)
sudo apt install ./package.deb    # preferred: resolves dependencies

Red Hat family: dnf and rpm

Terminal
sudo dnf check-update              # list available updates
sudo dnf upgrade                   # apply updates
sudo dnf install nginx
sudo dnf remove nginx
sudo dnf autoremove
dnf search "web server"
dnf info nginx
dnf provides /usr/sbin/nginx       # which package provides a file
dnf history                        # transactions; dnf history undo N reverts one
sudo dnf group install "Development Tools"

Low-level queries:

Terminal
rpm -qa | grep nginx        # installed packages
rpm -ql nginx               # files in package
rpm -qf /usr/sbin/nginx     # owner of file
rpm -qi nginx               # details

On older systems yum was the high-level tool; dnf is its successor and yum is often an alias to it.

Command comparison

Task Debian family Red Hat family
Refresh metadata apt update dnf makecache (automatic)
Upgrade all apt upgrade dnf upgrade
Install apt install p dnf install p
Remove apt remove p dnf remove p
Search apt search x dnf search x
Package of a file dpkg -S file rpm -qf file
Files in package dpkg -L p rpm -ql p
Installed list dpkg -l rpm -qa

SUSE uses zypper, Arch uses pacman, Alpine uses apk, with similar verbs.

How dependencies work

When you install nginx, the manager also installs libraries it needs. It builds a plan, shows it and asks confirmation. Always read the list: a surprising removal means something else depends on what you are removing.

flowchart TD
    A["install webapp"] --> B["needs libssl"]
    A --> C["needs libpq"]
    B --> D["needs libc"]
    C --> D
    D --> E["already installed"]

The manager resolves the graph and installs only what is missing.

Good habits

  1. Preview: use apt install -s pkg (simulate) or answer n at the dnf prompt to inspect a plan.
  2. Pin intent in automation: -y skips prompts, so test plans first.
  3. Keep one tool per system: do not mix apt with manual dpkg -i unless you must.
  4. Hold packages that must not change: apt-mark hold pkg or dnf versionlock.
  5. Check what changed: /var/log/apt/history.log and dnf history.
  6. Never install from random scripts as root without reading them.

A stand-in: dependency resolver

This model resolves a made-up dependency graph and prints the install order. Real managers do this with far more rules, but the idea is the same.

Python Stand-in: install order from dependencies

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A stand-in: compare versions

Package managers compare version strings piece by piece. This model compares simplified dotted versions numerically so 1.10 beats 1.9, which plain text sorting gets wrong.

Python Stand-in: version comparison

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Skipping apt update and installing outdated packages.
  • Using -y in production commands you have never previewed.
  • Forgetting purge when you want the old configuration gone.
  • Installing a package from a different release's repository, which can break dependencies.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does apt update do?

    It downloads indexes; apt upgrade installs newer versions.
  2. 2. Which command shows which package owns /usr/sbin/nginx on Red Hat systems?

    rpm -qf reports the owning package of a file.
  3. 3. What is the difference between apt remove and apt purge?

    remove keeps configuration; purge removes it too.
  4. 4. Why is apt install ./file.deb better than dpkg -i file.deb?

    dpkg does not fetch missing dependencies.

Summary

  • High-level tools (apt, dnf) resolve dependencies; low-level tools (dpkg, rpm) handle files.
  • Update indexes, preview the plan, then install or upgrade.
  • Query ownership and contents with dpkg -S/-L and rpm -qf/-ql.
  • Hold or lock packages that must not change.

Next: Repositories, Updates and Patching