Linux Package Management Reference: apt, dnf, pacman¶
Every major Linux distro has a package manager. The commands are different but the concepts are the same: install, remove, update, search. Here's the equivalent commands across the three you're most likely to encounter.
Common Tasks by Package Manager¶
| Task | apt (Debian/Ubuntu) | dnf (Fedora/RHEL) | pacman (Arch) |
|---|---|---|---|
| Update package index | apt update |
dnf check-update |
pacman -Sy |
| Upgrade all packages | apt upgrade |
dnf upgrade |
pacman -Su |
| Update index + upgrade | apt update && apt upgrade |
dnf upgrade |
pacman -Syu |
| Install a package | apt install pkg |
dnf install pkg |
pacman -S pkg |
| Remove a package | apt remove pkg |
dnf remove pkg |
pacman -R pkg |
| Remove + config files | apt purge pkg |
dnf remove pkg |
pacman -Rn pkg |
| Search for a package | apt search term |
dnf search term |
pacman -Ss term |
| Show package info | apt show pkg |
dnf info pkg |
pacman -Si pkg |
| List installed | apt list --installed |
dnf list installed |
pacman -Q |
| Which pkg owns file | dpkg -S /path/to/file |
rpm -qf /path/to/file |
pacman -Qo /path/to/file |
| List files in pkg | dpkg -L pkg |
rpm -ql pkg |
pacman -Ql pkg |
| Clean cache | apt clean |
dnf clean all |
pacman -Sc |
apt (Debian, Ubuntu, and derivatives)¶
# Always update before installing
sudo apt update
# Install
sudo apt install nginx
# Install multiple
sudo apt install nginx curl git
# Remove
sudo apt remove nginx
# Remove with config files
sudo apt purge nginx
# Autoremove orphaned dependencies
sudo apt autoremove
# Search
apt search nginx
# Show package details
apt show nginx
# Upgrade a specific package
sudo apt install --only-upgrade nginx
APT sources live in /etc/apt/sources.list and /etc/apt/sources.list.d/. Third-party PPAs go here. After adding a source, run apt update before installing from it.
dnf (Fedora, RHEL, AlmaLinux, Rocky)¶
# Update everything
sudo dnf upgrade
# Install
sudo dnf install nginx
# Remove
sudo dnf remove nginx
# Search
dnf search nginx
# Info
dnf info nginx
# List groups (collections of packages)
dnf group list
# Install a group
sudo dnf group install "Development Tools"
# History — see what was installed and when
dnf history
dnf history info <id>
# Undo a transaction
sudo dnf history undo <id>
dnf's history and undo features are underused and genuinely useful when you've installed something that broke things.
pacman (Arch, Manjaro)¶
# Full system update (do this before anything else, Arch is rolling)
sudo pacman -Syu
# Install
sudo pacman -S nginx
# Remove
sudo pacman -R nginx
# Remove with dependencies not needed by anything else
sudo pacman -Rs nginx
# Search
pacman -Ss nginx
# Info
pacman -Si nginx
# Query installed packages
pacman -Q # all installed
pacman -Qs nginx # search installed
pacman -Qi nginx # info on installed package
# Find orphaned packages
pacman -Qdt
# Clean package cache
sudo pacman -Sc # keep installed versions
sudo pacman -Scc # remove all cached packages
AUR (Arch User Repository) — packages not in the official repos. Use an AUR helper like yay or paru:
# Install yay
git clone https://aur.archlinux.org/yay.git
cd yay && makepkg -si
# Then use like pacman
yay -S package-name
Flatpak and Snap (Distro-Agnostic)¶
For software that isn't in your distro's repos or when you want a sandboxed installation:
# Flatpak
flatpak install flathub com.spotify.Client
flatpak run com.spotify.Client
flatpak update
# Snap
sudo snap install spotify
sudo snap refresh
Flatpak is what I prefer — better sandboxing story, Flathub has most things you'd want. Snap works fine but the infrastructure is more centralized.
Gotchas & Notes¶
- Always
apt updatebeforeapt install. Installing from a stale index can grab outdated versions or fail entirely. apt upgradevsapt full-upgrade:full-upgrade(ordist-upgrade) allows package removal to resolve conflicts. Use it for major upgrades.upgradewon't remove anything.- Arch is rolling — update frequently. Partial upgrades on Arch cause breakage. Always do
pacman -Syu(full update) before installing anything. - dnf is noticeably slower than apt on first run due to metadata downloads. Gets faster after the cache is warm.
- Don't mix package sources carelessly. Adding random PPAs (apt) or COPR repos (dnf) can conflict with each other. Keep third-party sources to a minimum.
See Also¶
- [[linux-distro-guide-beginners]]
- [[linux-server-hardening-checklist]]