Skip to content
Linux Package Management — apt, yum, dnf, and pacman Guide

Linux Package Management — apt, yum, dnf, and pacman Guide

DodaTech Updated Jun 7, 2026 9 min read

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
  
Prerequisites: A Linux system with any major distribution. Experience with essential Linux commands and basic Bash skills helps.

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 packages

Expected 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 footprint

Managing 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 update

yum 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 5

yum 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 AUR

Snap 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 version

Expected 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  classic

Flatpak — 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 runtimes

Comparison Table

Featureaptdnfpacmansnapflatpak
Distro familyDebian/UbuntuFedora/RHELArchAll (via snapd)All (via flatpak)
Package format.deb.rpm.pkg.tar.zstsquashfsOSTree
SandboxedNoNoNoYesYes
Rolling releaseNoNoYesChannel-basedNo
Auto-updatesNoNoNoYesNo
Best forServers, desktopsEnterprise serversPower usersIoT, cloudDesktop 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"
fi

Mini 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 -1

FAQ

What’s the difference between apt and apt-get?
apt is the newer, more polished frontend to APT. It combines commonly used commands from apt-get and apt-cache into a single command with better output. Both use the same backend.
How do I pin a package version to prevent automatic upgrades?
Use apt-mark hold package to prevent upgrades. To unhold: apt-mark unhold package. On dnf: add excludepkgs=package to /etc/dnf/dnf.conf. On pacman: modify /etc/pacman.conf with IgnorePkg = package.
What is a PPA and is it safe?
A PPA (Personal Package Archive) is a third-party repository on Launchpad. PPAs are convenient but trust the maintainer. Only add PPAs from reputable sources. Check the number of downloads and user reviews before adding.
Should I use snap or apt for server applications?
For servers, prefer apt (or dnf/pacman). Snaps auto-update, which can break production services unexpectedly. On servers, you control when updates happen. Snaps are better for desktop or IoT where automatic updates are beneficial.
How do I find out what a package will install before installing?
Use apt show package to see details and file list. On dnf: dnf repoquery -l package. On pacman: pacman -Fl package. These show every file the package will place on your system.

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