Linux Package Management: apt, dnf, yum, zypper, and pacman
Every distribution has its own package manager, but they all answer the same four questions: what is installed, what is available, how do I install or remove something, and how do I keep the system patched. This post maps the commands across the major families so you can move between Debian, RHEL, SUSE, and Arch without re-learning the basics.
The Two Families
- Debian family (Debian, Ubuntu, Mint):
apt/dpkg, packages are.deb. - RHEL family (RHEL, CentOS, Rocky, Alma, Fedora):
dnf(or legacyyum), packages are.rpm. - SUSE family (SLES, openSUSE):
zypper, packages are.rpm. - Arch family (Arch, Manjaro):
pacman, packages are.pkg.tar.zst.
Updating the Package Index
Before installing anything, refresh the metadata so you are not installing stale versions.
1
2
3
4
5
6
7
8
9
10
11
# Debian / Ubuntu
sudo apt update
# RHEL / Fedora
sudo dnf check-update
# SUSE
sudo zypper refresh
# Arch
sudo pacman -Sy
Tip: apt update refreshes metadata only. apt upgrade installs the updates. Running upgrade without update first is a common source of “package not found” errors.
Installing and Removing Packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Debian / Ubuntu
sudo apt install nginx
sudo apt remove nginx
sudo apt purge nginx # remove config files too
sudo apt autoremove # clean up orphaned dependencies
# RHEL / Fedora
sudo dnf install nginx
sudo dnf remove nginx
sudo dnf autoremove
# SUSE
sudo zypper install nginx
sudo zypper remove nginx
# Arch
sudo pacman -S nginx
sudo pacman -R nginx
sudo pacman -Rns nginx # remove deps and config
Tip: purge on Debian and -Rns on Arch remove configuration files as well. Use them when you want a truly clean reinstall.
Searching and Inspecting Packages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Search the repositories
apt search nginx
dnf search nginx
zypper search nginx
pacman -Ss nginx
# Show package details
apt show nginx
dnf info nginx
zypper info nginx
pacman -Si nginx
# List installed packages
apt list --installed
dnf list installed
zypper se --installed-only
pacman -Q
# Which package owns a file?
dpkg -S /usr/sbin/nginx
rpm -qf /usr/sbin/nginx
pacman -Qo /usr/sbin/nginx
# Which package *would* own it, even if not installed yet?
apt-file search bin/nginx
dnf provides '*/bin/nginx'
Tip: “Which package owns this file?” is the single most useful query when you inherit a system and need to know where a binary came from. dpkg -S and rpm -qf only know about installed packages; apt-file and dnf provides search the archive, so they also find packages you have not installed yet. Run sudo apt install apt-file && sudo apt-file update once on Debian.
Listing the Files a Package Installs
1
2
3
4
5
6
7
8
# Debian / Ubuntu
dpkg -L nginx
# RHEL / Fedora
rpm -ql nginx
# Arch
pacman -Ql nginx
Tip: dpkg -L is the fastest way to find the config file a package dropped somewhere unexpected, or to confirm a binary really came from the package you think it did.
Upgrading the System
1
2
3
4
5
6
7
8
9
10
11
12
13
# Debian / Ubuntu
sudo apt update && sudo apt upgrade
sudo apt full-upgrade # allows removing packages if needed
# RHEL / Fedora
sudo dnf upgrade
# SUSE
sudo zypper update
sudo zypper dup # distribution upgrade
# Arch
sudo pacman -Syu
Tip: On Arch, never do a partial upgrade (pacman -Sy followed by installing a single package). Always -Syu so the whole system stays consistent.
Holding and Pinning Versions
Sometimes you need to freeze a package at a specific version.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Debian / Ubuntu
sudo apt-mark hold nginx
sudo apt-mark unhold nginx
apt-mark showhold
# RHEL / Fedora
sudo dnf versionlock add nginx
sudo dnf versionlock delete nginx
# SUSE
sudo zypper addlock nginx
sudo zypper removelock nginx
# Arch
# Add to /etc/pacman.conf:
# IgnorePkg = nginx
Tip: apt-mark hold is the fastest way to stop an unattended-upgrades run from breaking a pinned service. On RHEL, versionlock comes from the dnf-plugins-core package.
Rolling Back a Bad Update
Holding a package stops the next upgrade. Rolling back undoes one that already happened.
1
2
3
4
5
6
7
# RHEL / Fedora: undo the last transaction
sudo dnf history
sudo dnf history undo last
# Debian / Ubuntu: install a specific older version
apt-cache policy nginx
sudo apt install nginx=1.18.0-6ubuntu14
Tip: Debian does not keep a transaction history like dnf. Pin the version explicitly, and keep the .deb files in /var/cache/apt/archives if you may need to reinstall an older build. apt-cache policy shows every available version and which one is the candidate.
Previewing Changes Before Applying Them
1
2
3
4
5
6
7
# Debian / Ubuntu
apt list --upgradable
sudo apt -s upgrade
# RHEL / Fedora
dnf check-update
sudo dnf upgrade --assumeno
Tip: apt -s and dnf --assumeno run the whole transaction and stop before committing. It is the fastest way to see exactly which packages would be added, removed, or upgraded.
Working with Local Package Files
1
2
3
4
5
6
7
8
9
10
# Install a local .deb
sudo dpkg -i package.deb
sudo apt install -f # fix missing dependencies
# Install a local .rpm
sudo dnf install ./package.rpm
sudo rpm -ivh package.rpm
# Install a local Arch package
sudo pacman -U package.pkg.tar.zst
Tip: dpkg -i does not resolve dependencies. Follow it with apt install -f to pull in whatever is missing.
Repository Configuration
1
2
3
4
5
6
7
8
9
10
11
12
13
# Debian / Ubuntu sources
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
# RHEL / Fedora repos
dnf repolist
ls /etc/yum.repos.d/
# SUSE repos
zypper repos
# Arch repos
cat /etc/pacman.conf
Tip: On modern Debian and Ubuntu, prefer files under /etc/apt/sources.list.d/ over editing /etc/apt/sources.list directly. It makes third-party repos easy to add and remove.
apt Pinning Deep Dive
Pinning lets you control which repository a package comes from, which is essential when mixing stable and backports.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# /etc/apt/preferences.d/99-pinning
Package: *
Pin: release a=stable
Pin-Priority: 900
Package: *
Pin: release a=backports
Pin-Priority: 100
# Show the effective priority for a package
apt-cache policy nginx
# Install from a specific release
sudo apt install -t backports nginx
Tip: apt-cache policy shows the candidate version and the priority of each source. It is the fastest way to understand why a package is not upgrading.
dnf module: Streams and Profiles
1
2
3
4
5
6
7
8
9
10
11
# List modules
dnf module list
# Enable a stream
sudo dnf module enable nodejs:20
# Install a profile
sudo dnf module install nodejs:20/development
# Reset a module
sudo dnf module reset nodejs
Tip: Module streams are how RHEL ships multiple versions of the same package. dnf module list shows which streams are available and which is enabled.
zypper Patterns
1
2
3
4
5
6
7
8
# List patterns
zypper patterns
# Install a pattern
sudo zypper install -t pattern lamp_server
# Search patterns
zypper search -t pattern
Tip: Patterns are SUSE’s way of grouping packages for a role. They are the equivalent of a meta-package on Debian.
pacman AUR
1
2
3
4
5
6
7
8
9
10
11
12
13
# Install an AUR helper
sudo pacman -S --needed base-devel git
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si
# Install from the AUR
yay -S google-chrome
# Search the AUR
yay -Ss chrome
# Update everything, including AUR
yay -Syu
Tip: The AUR is user-maintained and unvetted. Read the PKGBUILD before installing anything from it, because it runs arbitrary code as your user.
Quick Reference
| Task | Debian | RHEL | SUSE | Arch |
|---|---|---|---|---|
| Refresh index | apt update | dnf check-update | zypper refresh | pacman -Sy |
| Install | apt install | dnf install | zypper install | pacman -S |
| Remove | apt remove | dnf remove | zypper remove | pacman -R |
| Upgrade all | apt upgrade | dnf upgrade | zypper update | pacman -Syu |
| Search | apt search | dnf search | zypper search | pacman -Ss |
| File owner | dpkg -S | rpm -qf | rpm -qf | pacman -Qo |
Tip: Learn the four verbs — refresh, install, remove, upgrade — and you can operate any distribution. The flags differ, the mental model does not.
See Also
- Linux Disk Usage Tips — reclaiming space from package caches and orphaned dependencies.
