Catalog My learning Blog
Linux Command Line Tutorial for Developers · Phase 3 · Lesson 21 · 3 min read

Linux Package Management: apt vs yum

On this page
  1. Why use a package manager
  2. apt in practice on Ubuntu
  3. apt vs dnf vs yum command equivalents
  4. Holding and pinning package versions
  5. Safe package upgrade habits
  6. Check yourself

Why use a package manager

A program needs libraries, which need other libraries. A package manager resolves those dependencies, installs files to the right places (Day 6), verifies signatures, records what came from where, and upgrades or removes everything cleanly later.

Two families dominate:

FamilyDistributionsLow levelHigh level
DebianDebian, Ubuntudpkg (.deb)apt
Red HatRHEL, Fedora, Rocky, Alma, Amazon Linuxrpm (.rpm)dnf (older: yum)

apt in practice on Ubuntu

Refresh the package lists first; they're the catalog of what's available:

Shell
sudo apt update
apt-cache policy nginx
YAML
nginx:
  Installed: (none)
  Candidate: 1.28.3-2ubuntu1.11
  Version table:

Install, then check:

Shell
sudo apt install -y nginx
dpkg -s nginx | grep -E '^(Status|Version)'
YAML
Status: install ok installed
Version: 1.28.3-2ubuntu1.11

Dependencies were pulled in automatically:

Code
apt-cache depends nginx | head -6
Code
nginx
  Depends: libc6
  Depends: libcrypt1
  Depends: libpcre2-8-0
  Depends: libssl3t64
  Depends: zlib1g

Which package installed a file?

Code
dpkg -S /usr/sbin/nginx
Code
nginx: /usr/sbin/nginx
Package lists from signed repositories tell the package manager what's available; it resolves dependencies, installs files, and records them so upgrades and removals stay consistent.
Package lists from signed repositories tell the package manager what's available; it resolves dependencies, installs files, and records them so upgrades and removals stay consistent.

apt vs dnf vs yum command equivalents

Taskapt (Ubuntu, Debian)dnf (RHEL, Fedora)
Refresh metadataapt updatednf makecache (automatic)
Installapt install nginxdnf install nginx
Removeapt remove nginx (purge also removes config)dnf remove nginx
Upgrade allapt upgrade (full-upgrade allows removals)dnf upgrade
Searchapt search termdnf search term
Package infoapt show nginxdnf info nginx
Owner of a filedpkg -S /pathrpm -qf /path
Files in a packagedpkg -L nginxrpm -ql nginx
Clean cacheapt cleandnf clean all

Holding and pinning package versions

Pin a package so routine upgrades don't touch it (a database whose upgrade needs planning):

Shell
sudo apt-mark hold nginx
apt-mark showhold
Shell
nginx set on hold.
nginx

A simulated upgrade afterwards showed it held back: 36 upgraded, 0 newly installed, 0 to remove and 4 not upgraded. Remember to unhold (apt-mark unhold) and upgrade deliberately; held packages also miss security fixes. On dnf, the versionlock plugin does the same.

Safe package upgrade habits

  • Preview: apt-get -s upgrade (simulate) or apt list --upgradable.
  • Security updates automatically: unattended-upgrades on Ubuntu (enabled on the course VM, Day 27), dnf-automatic on RHEL.
  • Kernel and library updates often need a restart of services or a reboot; needrestart (Ubuntu) and dnf needs-restarting (RHEL) tell you which.
  • Use only trusted repositories. Third-party repositories are signed with their own keys, kept in /etc/apt/keyrings/ and referenced per repository rather than trusted globally.
  • For applications, prefer containers or language package managers with lockfiles; keep the OS package set small (Day 27).

Check yourself

It refreshes the local package lists from the repositories, so apt knows the current versions and where to download them. Without it, apt may try outdated versions that no longer exist on the mirror.

dpkg -S /path on Debian-based systems, and rpm -qf /path on Red Hat-based ones. It's useful for finding which package to reinstall or update.

It stops receiving updates, including security fixes, and can block upgrades of packages that depend on newer versions. Review holds regularly and record why each exists.

upgrade installs newer versions of installed packages but never removes any. full-upgrade also adds or removes packages when dependencies require it, which can matter for kernel and library transitions. Review what full-upgrade will remove before confirming.

Security patches then get applied within a day, without waiting for someone to log in and remember. Most compromises exploit known, already patched vulnerabilities, so shortening that window matters more than almost any other setting.