Direct Answer / TL;DR
Root cause: no universal package manager — backend format, solver, and repo layout differ per distro (dpkg/apt, rpm/dnf, libalpm/pacman, apk-tools). Fix: route every operation through the native manager — apt on Ubuntu 24.04/Debian 12, dnf on RHEL 9, pacman on Arch, apk on Alpine — and pre-verify each transaction with the native dry-run flag before mutating state.
apt-get -s install
Core Architecture & Mechanics
All four managers are userspace transaction engines layered over POSIX file semantics. None of them touches the kernel for package state: a transaction is a planned set of VFS operations (payload unpack via rename/unlink, maintainer scripts executed as root processes, metadata writes) against a filesystem root, with concurrency handled by advisory locks (flock) and integrity by repository-level signatures. What differs is the database format, the dependency solver, and how much of the transaction is buffered before touching the filesystem.
- dpkg + apt (Ubuntu 24.04, Debian 12): dpkg owns the state DB — the flat file /var/lib/dpkg/status plus per-package metadata in /var/lib/dpkg/info. apt/libapt handles index parsing, resolution, and download, then feeds dpkg an ordered queue. dpkg works in two stages: unpack everything, then configure in Pre-Depends-safe order, finally running deferred triggers. Locking: flock on /var/lib/dpkg/lock-frontend (frontend) and /var/lib/dpkg/lock (backend). Ubuntu 24.04 ships its repos as deb822 files in /etc/apt/sources.list.d/ubuntu.sources with inline Signed-By keyrings; Debian 12 keeps classic one-line sources and accepts deb822 optionally.
- rpm + dnf (RHEL/AlmaLinux 9): rpm is the backend — an sqlite-backed database under /var/lib/rpm (rpm 4.16 on EL9), scriptlets, and %config(noreplace) policy producing .rpmnew/.rpmsave. dnf/libdnf resolves with libsolv (a SAT solver) over repodata and records every transaction in /var/lib/dnf/history, the substrate for dnf history undo/rollback. Single-writer lock at /var/lib/rpm/.rpm.lock. RHEL/Alma 10 and Fedora 41+ replace the frontend with DNF5; the subcommand surface stays compatible, but output and some plugin paths differ.
- libalpm + pacman (Arch): state is one directory per package under /var/lib/pacman/local/<name>-<version>/ (desc, files, mtree). Sync databases are signed snapshots; mirrors live in /etc/pacman.d/mirrorlist. libalpm assumes whole-system consistency — partial upgrades are unsupported by design, making pacman -Sy <pkg> an error pattern. Conffile collisions always yield .pacnew files; hooks fire via alpm-hooks under /usr/share/libalpm/hooks.
- apk-tools (Alpine): a fully static musl-linked binary, ideal in containers, initramfs, and rescue chroots (apk –root /mnt). The installed set is defined solely by constraints in /etc/apk/world; every apk add/del re-solves the complete set deterministically. DB: /etc/apk/db/installed. Protected paths (via /etc/apk/protected_paths.d) leave edited configs as .apk-new siblings. Repos and tags: /etc/apk/repositories (main, community, @edge-style tags), signed indexes verified by .rsa.pub keys in /etc/apk/keys. Alpine edge ships apk-tools 3 with a compatible CLI.
Exit codes are first-order diagnostics: apt-get returns 100 on resolver/lock failures, 0 on success; dnf check-update uses 100 to mean updates-available and 1 for a genuine failure; pacman and apk return non-zero (typically 1) on any error. Conffile handling differs sharply: dpkg prompts (or obeys –force-confdef/–force-confold), rpm emits .rpmnew/.rpmsave per scriptlet policy, pacman always drops .pacnew, apk drops .apk-new for protected paths. No manager merges configs for you.
Complete Reference Table / Diagnostic Matrix
Operation-level mapping across the four stacks. Simulate every mutating row first: apt-get -s, dnf –assumeno, pacman -Sp, apk -s.
| Item / Code / Flag | Behavior | Common Cause / Use Case |
|---|---|---|
| Refresh metadata | apt-get update · dnf makecache –refresh · pacman -Sy · apk update | Stale index after mirror/branch changes causes 404s; on Arch, -Sy alone (partial DB) is forbidden — always pair with -u. |
| Install | apt-get install <p> · dnf install <p> · pacman -S <p> · apk add <p> | Baseline mutation; pre-verify with the dry-run row on shared hosts. |
| Dry-run | apt-get -s install <p> · dnf install –assumeno <p> · pacman -Sp <p> · apk add -s <p> | Resolver preview with zero filesystem writes; mandatory habit before production changes. |
| Full upgrade | apt full-upgrade · dnf upgrade · pacman -Syu · apk upgrade –available | Kernel/libc sync point; Arch accepts only -Syu as a complete transaction. |
| List upgradable | apt list –upgradable · dnf check-update (RC 100 = updates) · pacman -Qu · apk version -l ‘<‘ | Automation polling; dnf’s 100 is success data, not failure. |
| Search remote | apt-cache search <rx> · dnf search <t> · pacman -Ss <rx> · apk search -v <rx> | Name/summary discovery across enabled repos. |
| Search installed | apt list –installed <pat> · dnf list installed <pat> · pacman -Qs <t> · apk list -I | Local state audit before removals or version pins. |
| Package metadata | apt show <p> · dnf info <p> · pacman -Si / -Qi <p> · apk info -a <p> | Deps, sizes, versions; -Si queries repo copy, -Qi the installed one. |
| Payload files | dpkg -L <p> · rpm -ql <p> · pacman -Ql <p> · apk info -L <p> | Pre-removal audits and conflict checks before side-loading. |
| File ownership | dpkg -S <file> · rpm -qf <file> (+ dnf provides <glob>) · pacman -Qo <file> (+ pacman -F <file> after -Fy) · apk info -W <file> | Ownership disputes; probing not-installed files needs remote DBs (apt-file, dnf provides, pacman -F). |
| Integrity verify | dpkg -V <p> · rpm -V <p> · pacman -Qkk <p> · apk audit <p> | Post-crash or tamper check: diff installed files vs the DB manifest. |
| Remove | apt-get remove|purge <p> · dnf remove <p> · pacman -Rns <p> · apk del <p> | -Rns drops auto-installed deps and configs; apk re-solves world and prunes freed deps implicitly. |
| Orphan sweep | apt-get -s autoremove · dnf autoremove · pacman -Rns $(pacman -Qdtq) · apk (implicit) | Always print the target list first; run only inside maintenance windows. |
| Repair | dpkg –configure -a + apt-get -f install · dnf distro-sync · pacman -Syu · apk fix | Interrupted or half-applied transactions, missing payload files. |
| Downgrade | apt-get install <p>=<v> · dnf downgrade <p> · pacman -U <cached-old.pkg> · apk add ‘<p>=<old>’ | Regression containment; pacman/apk serve previous artifacts from local cache. |
| Version hold | apt-mark hold <p> · dnf versionlock add <spec> (or exclude= in dnf.conf) · IgnorePkg= in pacman.conf · ‘<p>=<v>’ kept in world | Kernels, drivers, DB engines during change freezes. |
| Transaction log | /var/log/apt/history.log, /var/log/dpkg.log · dnf history · /var/log/pacman.log · world file + syslog (apk) | Post-incident forensics; only dnf has a first-class undo database. |
| Rollback last txn | apt: reinstall <p>=<old> · dnf history undo last · pacman -U cached predecessor · apk re-pin ‘<p>=<old>’ | Failed-upgrade reversal; re-verify with the integrity row afterwards. |
| Cache clean | apt-get clean · dnf clean all · pacman -Sc / -Scc · apk cache clean | /var growth; -Scc wipes every cached tarball — cache only, but irreversible. |
| Repo config | /etc/apt/sources.list.d/*.sources · /etc/yum.repos.d/*.repo · /etc/pacman.conf + /etc/pacman.d/mirrorlist · /etc/apk/repositories | Mirror/branch changes; keyring placement sits beside each format. |
| Local file install | apt-get install ./<f.deb> · dnf install ./<f.rpm> · pacman -U ./<f> · apk add –allow-untrusted ./<f.apk> | Self-built archives; untrusted flags only inside sandboxes or VMs. |
Multi-Distro Implementation Differences
Working sequences per family, including diagnostics and rollback paths.
Ubuntu / Debian
sudo apt-get update
apt list --upgradable
sudo apt-get -s install nginx # simulate (no dpkg writes)
sudo apt-get install -y nginx
# Interrupted-upgrade recovery, in this order
sudo dpkg --configure -a
sudo apt-get -f install
dpkg --audit # half-installed/half-configured pkgs
# Holds and forensic trail
apt-mark showhold
tail -n 30 /var/log/apt/history.log
# Servers: never let conffile prompts block an unattended job
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold upgradeRHEL / AlmaLinux / Rocky
sudo dnf makecache --refresh
dnf check-update # RC 100 = updates available, 1 = real error
sudo dnf install -y nginx
dnf history list | head -n 8
dnf history info last # scriptlets run, packages touched, result
sudo dnf history undo last # transaction-level rollback (review, then confirm)
sudo dnf provides '*/bin/saslpasswd2' # resolve a file to its owning package
rpm -V nginx # verify payload vs the rpm DB
sudo dnf config-manager --set-enabled crb
sudo dnf clean all && sudo dnf makecache # reset stale/403 metadata
# Pin critical updates in /etc/dnf/dnf.conf: exclude=kernel*,kmod-*Arch Linux
sudo pacman -Syu # refresh + upgrade; never -Sy alone
sudo pacman -S nginx
pacman -Qdt # orphan review (read-only)
pacman -Rns $(pacman -Qdtq) # destructive: confirm the -Qdt list first
pacman -Qkk nginx # checksum every payload file vs DB
pacman -Fy && pacman -F /etc/nginx/nginx.conf # remote file search (files DB)
sudo pacman -Sy archlinux-keyring && sudo pacman -Su # stale keyring fix
grep -E '^(IgnorePkg|HoldPkg)' /etc/pacman.conf
pgrep -a pacman || echo 'no pacman running: db.lck may be stale'Alpine / Containers
sudo apk update
apk add -s nginx # simulate against the current world
sudo apk add nginx
apk info -W /usr/sbin/nginx # file to owning package
apk info -e nginx || echo missing # scripted presence check (RC 1 if absent)
apk audit | head -n 20 # modified/new/missing files vs DB
sudo apk fix # reinstall broken/missing payloads
sudo apk upgrade --available # respects world version pins
sudo apk add 'nginx=1.26*' # quoted pin persists in /etc/apk/world
# chroot/rescue bootstrap: apk --root /mnt --initdb add alpine-baseBranch notes: DNF5 (Alma/RHEL 10, Fedora 41+) keeps the same subcommand names, but CI should exercise scripts against dnf5 explicitly; check-update and history semantics are the first things to re-verify. Alpine edge runs apk-tools 3.x with CLI compatibility — its world solver never silently rewrites your pins. On Debian-family hosts, prefer deb822 .sources files for hand-maintained repos; dpkg-conffile automation belongs in Dpkg::Options, not expect scripts.
Common Failure Modes & Troubleshooting Recipes
Diagnose by layer: lock state first, transaction history second, file-vs-database verification third. Recipes run from non-mutating checks to gated fixes.
1. apt: dpkg frontend lock held (unattended-upgrades)
Signature: E: Could not get lock /var/lib/dpkg/lock-frontend – open (11: Resource temporarily unavailable). On Ubuntu 24.04 the usual holder is unattended-upgrades under apt-daily-upgrade.timer (roughly 06:00/18:00 plus RandomizedDelaySec). Killing dpkg mid-transaction corrupts its queue; wait the holder out instead.
fuser -v /var/lib/dpkg/lock-frontend /var/lib/dpkg/lock 2>&1
pgrep -a unattended-upgr || echo 'no updater running'
# wait; re-run fuser until it prints no PID, then:
sudo dpkg --configure -a
sudo apt-get -f install
sudo apt-get -s autoremove --purge # review the list, then execute for realNever delete lock files to force progress — locks are recreated on demand and removing them only removes the warning about a live process.
2. dnf: failed transaction or stale metadata (RHEL/Alma 9)
A scriptlet error leaves the transaction failed in history rather than half-done on disk; use the history DB as the source of truth. Metadata-only symptoms (403s, No such file for repomd) are cache corruption from mirror/proxy desync.
dnf history list | head -n 8
dnf history info last # scriptlets, packages, success flag
sudo dnf history undo last # review the inverse transaction, then confirm
sudo dnf clean all && sudo dnf makecache --refresh # stale/403 metadata reset
rpm -V openssh-server # per-file verify against the RPM DB3. pacman: stale keyring, db.lck, orphans (Arch)
Unknown signature or key errors after a machine has been offline for months are keyring staleness: update archlinux-keyring before doing anything else. A db.lck left after a crash is removed only once no pacman process exists. Partial-upgrade symptoms (symbol lookup errors in linked binaries) are fixed by completing the upgrade, not by downgrading.
sudo pacman -Sy archlinux-keyring && sudo pacman -Su
pgrep -a pacman || sudo rm /var/lib/pacman/db.lck # moderate: only if pgrep printed nothing
pacman -Qkk nginx # payload integrity vs DB manifest
pacman -Qdt # review orphans (read-only)
pacman -Rns $(pacman -Qdtq) # destructive sweep; confirm the printed list4. apk: world conflicts and .apk-new drift (Alpine)
Conflicting pins surface as ERROR: unable to select packages: — the resolver prints every constraint candidate that collided. Fix the world file, never force it in automation. Modified protected configs survive upgrades as path.apk-new siblings; audit and diff before deleting.
cat /etc/apk/world # constraints that caused the conflict
apk add -s 'nginx=1.26*' # verify a pin resolves before committing
apk audit | head -n 20 # drift vs the package DB
sudo apk fix # reinstall missing/broken payloads
sudo apk upgrade --available
find /etc -name '*.apk-new' -print
diff /etc/ssh/sshd_config /etc/ssh/sshd_config.apk-new 2>&1 | head
sudo rm /etc/ssh/sshd_config.apk-new # destructive: only after the diff is decidedProduction Hardening & Safety Checklist
Safety Check: Every destructive row above (autoremove –purge, the -Rns orphan sweep, -Scc cache purge, lock-file or .apk-new removal) is gated in this guide by a read-only preview or a pgrep check. Keep that gating in your own runbooks: preview the target set, snapshot state, mutate, then verify with the native integrity command (dpkg -V / rpm -V / pacman -Qkk / apk audit).
- Simulate first, always: apt-get -s, dnf –assumeno, pacman -Sp, apk -s — on every host class, not just production.
- Never automate signature bypasses (–nogpgcheck, –allow-untrusted, apt –allow-unauthenticated). Expired keys are keyring-rotation tasks: pacman -Sy archlinux-keyring, rpm –import, or swapping the deb822 Signed-By keyring.
- Back up state before full syncs on Ubuntu:
tar -C / -czf /root/pkg-db-$(date +%F).tar.gz var/lib/dpkg/status /etc/apt/sources.list.d; on btrfs/LVM hosts prefer a read-only pre-upgrade snapshot over file copies. - Check headroom before kernel or libc transactions:
df -h / /var. Package caches are the first legitimate reclaim (apt-get clean, paccache -rk2, dnf clean, apk cache clean). - Pin kernels: apt-mark hold linux-generic; exclude=kernel* in /etc/dnf/dnf.conf; IgnorePkg = linux linux-headers in pacman.conf; a persisted ‘linux-lts=6.6*’ constraint in /etc/apk/world.
- Run long transactions inside tmux; after any disconnect, re-check locks (fuser, pgrep) before retrying.
- Integrate config leftovers after upgrades: rpmconf -a (dnf-plugins-extras), pacdiff (pacman-contrib), manual diff for .apk-new and .dpkg-dist files.
- Rollback anchors: dnf history undo last; pacman -U from the cached predecessor; apk re-pin to the old EVR; apt reinstall of pkg=oldversion — then re-run the verify command.
Frequently Asked Edge Cases
Why does dnf check-update exit with 100 and is that an error?
No — DNF uses 100 to mean updates are available, 0 for none, and 1 for a genuine failure. Automate it as success data: `[ $? -eq 100 ]` triggers the apply job, while 1 pages an operator.
Is pacman -Sy ever safe?
No. -Sy refreshes the sync DB ahead of installed packages but upgrades only the target, violating Arch's whole-system consistency; linked binaries then resolve against mismatched libs. Always run pacman -Syu; -S alone against an existing up-to-date DB is fine.
How do I hold a critical package on all four systems?
Run `apt-mark hold linux-generic` (undo: unhold), add `exclude=kernel*` to /etc/dnf/dnf.conf or use `dnf versionlock add`, set `IgnorePkg = linux` in /etc/pacman.conf, and keep a pinned constraint like `'linux-lts=6.6*'` in /etc/apk/world so the pin survives normal upgrades.
