Package managers are how Linux systems install, update, and remove software. Instead of downloading installers from websites, Linux uses curated repositories with dependency resolution built in. This guide covers apt (Debian/Ubuntu) and dnf/yum (RHEL/Rocky/Fedora) — the two package ecosystems you will encounter most on servers.
How Package Management Works
A package manager maintains a local cache of available packages from configured repositories. When you install a package, the manager resolves dependencies, downloads the packages, verifies GPG signatures, and installs files to the correct paths.
apt — Debian and Ubuntu
Basic Operations
sudo apt update # Refresh local package index
sudo apt upgrade -y # Upgrade all installed packages
sudo apt full-upgrade -y # Upgrade + handle dependency changes
sudo apt install nginx # Install nginx
sudo apt install nginx curl wget # Install multiple packages
sudo apt remove nginx # Remove package (keep config)
sudo apt purge nginx # Remove package AND config files
sudo apt autoremove # Remove unused dependency packages
Searching and Inspecting
apt search nginx # Search available packages
apt show nginx # Detailed info about package
apt list --installed # All installed packages
apt list --installed | grep nginx # Check if nginx is installed
apt-cache depends nginx # Show dependencies
dpkg -l nginx # dpkg-level info
Managing Repositories
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
# Add a PPA (Ubuntu)
sudo add-apt-repository ppa:ondrej/php
sudo apt update
Holding Packages (Prevent Upgrade)
sudo apt-mark hold nginx # Prevent nginx from being upgraded
sudo apt-mark unhold nginx # Re-allow upgrades
apt-mark showhold # List held packages
dnf — Fedora, Rocky Linux, RHEL, AlmaLinux
dnf replaced yum as the default on RHEL 8+ and Fedora. Most yum commands work identically with dnf.
Basic Operations
sudo dnf check-update # Check for updates
sudo dnf upgrade -y # Upgrade all packages
sudo dnf install nginx -y # Install nginx
sudo dnf remove nginx # Remove nginx
sudo dnf autoremove # Remove unused dependencies
Searching and Inspecting
dnf search nginx # Search packages
dnf info nginx # Detailed package info
dnf list installed # Installed packages
dnf repoquery --requires nginx # Show dependencies
rpm -qi nginx # RPM-level package info
Managing Repositories
dnf repolist # List enabled repos
dnf repolist all # All repos including disabled
sudo dnf install epel-release -y # EPEL repository
sudo dnf install --enablerepo=epel nginx # Install from specific repo
Package Groups
dnf group list # List available groups
sudo dnf group install "Development Tools"
sudo dnf group install "Web Server"
Cleaning Up
# apt
sudo apt clean # Clear downloaded package files
sudo apt autoremove # Remove unneeded dependencies
# dnf
sudo dnf clean all # Clear all cached data
sudo dnf clean packages # Clear only downloaded packages
History and Rollback (dnf)
dnf history # Show transaction history
dnf history info 15 # Details of transaction 15
sudo dnf history undo 15 # Undo transaction 15 (rollback)
Summary
Package management is fundamental to Linux administration. On Debian/Ubuntu, apt update before every install is a habit worth forming. On RHEL-family systems, dnf provides the same functionality. Both systems use signed packages from trusted repositories, making software installation far safer and more maintainable than manual downloads.