Package Management: apt, dnf, pacman
Three package managers cover most Linux systems in production: apt on Debian and Ubuntu, dnf on Fedora and RHEL family, pacman on Arch and derivatives. They solve the same problem with different vocabulary. Knowing the rosetta stone saves time on every box that isn't your daily driver.
The common operations
| Operation | apt | dnf | pacman |
|---|---|---|---|
| Refresh metadata | apt update | dnf check-update | pacman -Sy |
| Upgrade all | apt upgrade | dnf upgrade | pacman -Syu |
| Install | apt install foo | dnf install foo | pacman -S foo |
| Remove | apt remove foo | dnf remove foo | pacman -R foo |
| Search | apt search foo | dnf search foo | pacman -Ss foo |
| Show info | apt show foo | dnf info foo | pacman -Si foo |
| List installed | apt list --installed | dnf list installed | pacman -Q |
| Which pkg owns file | dpkg -S /path | dnf provides /path | pacman -Qo /path |
Repository configuration
apt reads /etc/apt/sources.list and files in /etc/apt/sources.list.d/. Each line specifies a URL, suite, and components. Third-party repos add a file to sources.list.d/ and a signing key under /etc/apt/keyrings/.
dnf reads /etc/yum.repos.d/*.repo, INI-format. Each repo has its own file with URL, gpgcheck, enabled.
pacman reads /etc/pacman.conf for repos and /etc/pacman.d/mirrorlist for the URL list.
The lock file
All three serialize package operations behind a lock file. If you see "Could not get lock /var/lib/dpkg/lock" or similar, another process (often unattended-upgrades, packagekit, or a leftover apt session) is running. Don't rm the lock — find the process:
sudo lsof /var/lib/dpkg/lock-frontend # apt
sudo lsof /var/lib/rpm/.rpm.lock # dnf
sudo lsof /var/lib/pacman/db.lck # pacman
Holding versions
Pinning a package to a specific version, or preventing an upgrade:
# apt
apt-mark hold nginx
# dnf
dnf versionlock add nginx-1.24.0
# pacman (edit /etc/pacman.conf)
IgnorePkg = nginx
Clean up
apt autoremove # remove orphaned dependencies
apt clean # wipe /var/cache/apt/archives
dnf autoremove
dnf clean all
pacman -Rns $(pacman -Qtdq) # orphaned deps
paccache -r # keep last 3 versions
When things break
Half-installed package on Debian: dpkg --configure -a. Broken dependencies: apt install -f. RPM database corruption: rpm --rebuilddb. pacman keyring issues: pacman-key --refresh-keys.