Linux Package Management — apt, yum, dnf, and pacman Guide
Package managers are the most important tools for installing, updating, and removing software on Linux. Each distribution family uses a different package manager, but the concepts are universal. This guide covers apt, yum, dnf, pacman, and modern universal package formats.
What You’ll Learn
By the end of this tutorial, you’ll know how to use apt (Debian/Ubuntu), yum and dnf (RHEL/Fedora), and pacman (Arch Linux) for package management. You’ll understand repository management, dependency resolution, and when to use snap or flatpak.
Why Package Management Matters
Manually compiling and installing software is time-consuming and error-prone. Package managers handle dependencies automatically, verify package integrity with GPG signatures, and make updates painless. At DodaTech, DodaZIP and Durga Antivirus Pro are distributed via package repositories and kept up to date across thousands of Linux servers.
Package Management Learning Path
flowchart LR
A[Linux Basics] --> B[Server Setup]
B --> C[Essential Commands]
C --> D[System Administration]
D --> E[Package Management]
E --> F{You Are Here}
style F fill:#f90,color:#fff
apt — Debian, Ubuntu, and Derivatives
apt (Advanced Package Tool) is the most widely used package manager, thanks to Ubuntu’s popularity. It uses .deb packages.
# Update package index (always run first)
sudo apt update
# Upgrade all packages
sudo apt upgrade
sudo apt full-upgrade # Handles dependency changes
# Install and remove
sudo apt install nginx
sudo apt remove nginx # Remove but keep config files
sudo apt purge nginx # Remove including config files
sudo apt autoremove # Remove unused dependencies
# Search and info
apt search "web server"
apt show nginx
# List installed
apt list --installed
apt list --upgradable
# Clean up
sudo apt autoclean # Remove old cached packages
sudo apt clean # Clear all cached packagesExpected output from apt search "web server":
Sorting... Done
Full Text Search... Done
nginx/focal-updates,focal-security 1.24.0-2ubuntu7 amd64
small, powerful, scalable web/proxy server
apache2/focal-updates,focal-security 2.4.58-1ubuntu8.4 amd64
Apache HTTP Server
lighttpd/focal 1.4.55-1ubuntu1 amd64
fast webserver with minimal memory footprintManaging Repositories
# Add a PPA (Personal Package Archive)
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php8.3
# View repository list
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
# Add a third-party repository manually
echo "deb https://packages.example.com/ubuntu focal main" | sudo tee /etc/apt/sources.list.d/example.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys KEYID
sudo apt updateyum and dnf — RHEL, CentOS, Fedora
yum (Yellowdog Updater Modified) is the traditional package manager for RPM-based distros. dnf is its modern replacement, default in Fedora and RHEL 8+.
dnf examples (Fedora, RHEL 8+, CentOS Stream)
# Update package index
sudo dnf check-update
# Install and upgrade
sudo dnf install nginx
sudo dnf upgrade
sudo dnf upgrade nginx
# Remove
sudo dnf remove nginx
sudo dnf autoremove # Remove orphaned packages
# Search and info
dnf search "web server"
dnf info nginx
dnf provides /usr/bin/nginx # Find which package provides a file
# Group operations
sudo dnf groupinstall "Development Tools"
sudo dnf group list
# History and rollback
dnf history
sudo dnf history undo 5yum examples (CentOS 7, older systems)
yum commands are nearly identical to dnf:
sudo yum install nginx
sudo yum update
sudo yum remove nginx
yum search nginx
yum info nginx
sudo yum groupinstall "Development Tools"Expected output from dnf info nginx:
Installed Packages
Name : nginx
Version : 1.24.0
Release : 1.fc40
Architecture : x86_64
Size : 1.4 M
Source : nginx-1.24.0-1.fc40.src.rpm
Repository : @system
Summary : A high performance web server and reverse proxy server
URL : https://nginx.org/pacman — Arch Linux and Manjaro
Arch Linux uses pacman and a rolling release model — install once, update forever.
# Synchronize and update
sudo pacman -Syu # Update package database AND upgrade all
# Install and remove
sudo pacman -S nginx # Install
sudo pacman -R nginx # Remove
sudo pacman -Rs nginx # Remove with dependencies
sudo pacman -Rn nginx # Remove with config files
# Search and info
pacman -Ss "web server" # Search packages
pacman -Si nginx # Package info
pacman -Qi nginx # Installed package info
pacman -Ql nginx # List files owned by package
# Orphans and cleanup
pacman -Qdt # List orphaned packages
sudo pacman -Rns $(pacman -Qdtq) # Remove orphans
# AUR (Arch User Repository) using yay helper
yay -S google-chrome # Install from AURSnap Packages
Snaps are containerized packages that work across all Linux distributions. Developed by Canonical (Ubuntu).
# Install snap support
sudo apt install snapd
# Install and manage snaps
sudo snap install lxd
sudo snap install --classic certbot
sudo snap list # List installed snaps
sudo snap refresh # Update all snaps
sudo snap remove lxd
# Snap channels and versions
sudo snap install --channel=edge lxd
sudo snap revert lxd # Rollback to previous versionExpected output from snap list:
Name Version Rev Tracking Publisher Notes
core20 20260302 2594 latest/stable canonical✓ base
lxd 5.21.2-af76e4c 30297 latest/stable canonical✓ -
certbot 2.10.0 3417 latest/stable certbot-eff classicFlatpak — Universal Linux Apps
Flatpak focuses on desktop applications, providing sandboxed environments across distros.
# Install flatpak
sudo apt install flatpak
# Add Flathub repository
sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
# Install and run
flatpak install flathub org.gimp.GIMP
flatpak run org.gimp.GIMP
# Manage
flatpak list # List installed
flatpak update # Update all
flatpak uninstall org.gimp.GIMP
flatpak uninstall --unused # Remove unused runtimesComparison Table
| Feature | apt | dnf | pacman | snap | flatpak |
|---|---|---|---|---|---|
| Distro family | Debian/Ubuntu | Fedora/RHEL | Arch | All (via snapd) | All (via flatpak) |
| Package format | .deb | .rpm | .pkg.tar.zst | squashfs | OSTree |
| Sandboxed | No | No | No | Yes | Yes |
| Rolling release | No | No | Yes | Channel-based | No |
| Auto-updates | No | No | No | Yes | No |
| Best for | Servers, desktops | Enterprise servers | Power users | IoT, cloud | Desktop apps |
Common Package Management Mistakes
1. Running apt upgrade Without apt update First
apt upgrade only upgrades packages already in the local index. If you don’t run apt update first, you’ll miss new versions. Always run apt update && apt upgrade together.
2. Mixing Package Managers for the Same Software
Installing Python via apt, pip, and snap on the same system creates conflicts. Choose one source per application. For system packages, prefer the distribution package manager.
3. Pinning or Holding Packages Without Understanding
apt-mark hold package prevents upgrades. This is useful for critical packages, but forgetting about held packages means missing security updates. Document all held packages.
4. Ignoring GPG Key Warnings
When adding repositories, you’ll see GPG key warnings. Skipping key verification is dangerous — you might install tampered packages. Always verify keys come from the official source.
5. Removing Packages Without Checking Dependencies
sudo apt remove package only removes the package. sudo apt autoremove cleans up unused dependencies. But sudo apt purge removes config too — you might lose custom configurations.
6. Using sudo pip install Instead of System Packages
sudo pip install installs Python packages system-wide, bypassing the package manager. This can break system Python. Use pip install --user or a virtual environment instead.
7. Not Rebooting After Kernel Updates
When a new kernel is installed via apt upgrade, the running system still uses the old kernel until reboot. Use uname -r to check the current kernel and reboot if it doesn’t match the latest installed.
Practice Questions
1. What’s the difference between apt install and apt-get install?
apt has a more user-friendly interface with progress bars and color output. apt-get is more stable for scripting. For daily use, apt is recommended. For scripts, use apt-get.
2. How do you find which package provides a command in RHEL-based systems?
Use dnf provides /usr/bin/command or dnf whatprovides command. For example, dnf provides /usr/bin/nginx shows which package provides the nginx binary.
3. What does the -Syu flag in pacman -Syu mean?
-S synchronizes packages, -y refreshes the package database, -u upgrades all out-of-date packages. Together, it’s the equivalent of apt update && apt upgrade.
4. When should you use snap or flatpak instead of the system package manager?
When you need a newer version than what’s in the system repository, want sandboxed applications, or need to run the same version across different distributions. Snap is better for CLI/server tools; flatpak is better for desktop GUI apps.
5. Challenge: Write a script that checks for available updates across all package managers and reports the count.
Answer:
#!/bin/bash
echo "=== Update Check ==="
apt_updates=$(apt list --upgradable 2>/dev/null | grep -c upgradable)
echo "apt (Debian/Ubuntu): $apt_updates updates"
if command -v dnf &>/dev/null; then
dnf_updates=$(dnf check-update --quiet 2>/dev/null | wc -l)
echo "dnf (Fedora/RHEL): $dnf_updates updates"
fi
if command -v pacman &>/dev/null; then
pacman_updates=$(pacman -Qu 2>/dev/null | wc -l)
echo "pacman (Arch): $pacman_updates updates"
fiMini Project: Multi-Distro Package Install Script
Create a script that installs common packages regardless of distribution:
#!/bin/bash
# install_common.sh — Install common packages across distros
# Usage: sudo ./install_common.sh
# Detect distribution
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
OS_LIKE=$ID_LIKE
fi
install_packages() {
case "$OS" in
ubuntu|debian|pop|linuxmint)
sudo apt update
sudo apt install -y curl wget git htop nmon \
build-essential net-tools
;;
fedora|rhel|centos)
if command -v dnf &>/dev/null; then
sudo dnf install -y curl wget git htop nmon \
make gcc-c++ net-tools
else
sudo yum install -y curl wget git htop nmon \
make gcc-c++ net-tools
fi
;;
arch|manjaro|endeavour)
sudo pacman -Syu --noconfirm curl wget git htop nmon \
base-devel net-tools
;;
*)
echo "Unsupported distribution: $OS"
exit 1
;;
esac
}
echo "Detected OS: $OS"
install_packages
echo "Installation complete!"
# Show installed versions
echo "=== Installed Versions ==="
curl --version | head -1
git --version
htop --version 2>/dev/null | head -1FAQ
What’s Next
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro