Package Manager
A Linux package manager installs, updates, and removes software packages along with their dependencies. apt manages .deb packages on Debian/Ubuntu. yum and dnf manage .rpm packages on RHEL/CentOS/Amazon Linux. Both verify package integrity with GPG signatures before installation.
Understanding Linux Package Managers
What Is a Package Manager in Simple Terms
A package manager is an automated software librarian. Instead of downloading source code, compiling it, placing files in the right directories, and tracking what you installed, a package manager does all of this automatically. It also knows about dependencies — if nginx needs OpenSSL, it installs OpenSSL first.
How It Works
+------------------------------------------+| apt install nginx |+------------------------------------------+ | v+------------------------------------------+| Check local package index || /var/lib/apt/lists/ -- run apt update |+------------------------------------------+ | v+------------------------------------------+| Resolve dependencies || nginx needs: libssl, libpcre, zlib |+------------------------------------------+ | v+------------------------------------------+| Download packages from repository || Verify GPG signature |+------------------------------------------+ | v+------------------------------------------+| Install to correct locations || /usr/sbin/nginx, /etc/nginx/, /lib/... || Register systemd unit |+------------------------------------------+Practical Commands
## ── Debian/Ubuntu (apt) ────────────────────────────────── ## Update package index (must run before installing)sudo apt update ## Install packagesudo apt install nginx ## Install specific versionsudo apt install nginx=1.24.0-1ubuntu1 ## Remove package (keep config)sudo apt remove nginx ## Remove package and config filessudo apt purge nginx ## Upgrade all packagessudo apt upgrade ## Search for a packageapt search nginxapt-cache show nginx ## show package details ## List installed packagesdpkg -ldpkg -l | grep nginx ## Find which package owns a filedpkg -S /usr/sbin/nginx## nginx: /usr/sbin/nginx ## List files installed by a packagedpkg -L nginx ## Pin a package version (prevent auto-upgrade)sudo apt-mark hold nginxsudo apt-mark showhold ## list held packages ## ── RHEL/Amazon Linux (yum/dnf) ────────────────────────── sudo yum install nginx ## or dnf install nginxsudo yum remove nginxsudo yum updateyum search nginxyum info nginxrpm -qa | grep nginx ## list installed RPM packagesrpm -ql nginx ## list files in packagerpm -qf /usr/sbin/nginx ## which package owns this fileTroubleshooting
| Symptom | Command | What to Check |
|---|---|---|
| Package not found | sudo apt update then retry |
Index is stale |
| Wrong version installed | apt-cache policy pkgname |
Which repo provides it |
| Dependency conflict | sudo apt install -f |
Fix broken dependencies |
| GPG error adding repo | Import the signing key | `curl key |
Remember
apt updateupdates the local index of available packages — it does NOT install or upgrade anything. It must be run beforeapt installto ensure you get current package versions. Forgetting this is why servers end up with outdated versions installed.
SecurityOnly add repositories from trusted sources with verified GPG keys. A malicious repository can serve packages that replace system binaries with compromised versions. Always verify the GPG key fingerprint against the vendor's official website before adding any third-party repository.
Frequently Asked Questions
Why do apt and yum/dnf handle dependency resolution differently in practice?
apt (Debian/Ubuntu) resolves dependencies using APT's resolver against `.deb` packages and a package index refreshed with `apt update`, while yum/dnf (RHEL/CentOS/Amazon Linux/Fedora) resolves `.rpm` packages, with dnf being the modern resolver that replaced yum's slower, less reliable dependency solver starting with RHEL 8/Fedora 22. Both verify package authenticity via GPG signatures before install, but the package formats, repository metadata structure, and CLI syntax are not interchangeable — a `.deb` won't install via `rpm` or vice versa without conversion tools.
What's a common production mistake when managing packages on a Linux server?
Running `apt upgrade` (or `dnf upgrade`) directly against production without pinning versions or testing in staging first can pull in a breaking change from an upstream repo update, since these commands upgrade to whatever the latest available version is at that moment, not a tested one. A safer production pattern is pinning critical package versions explicitly, using a private/mirrored repository for reproducibility, and only ever upgrading through a tested, version-controlled process rather than an ad hoc `upgrade` on a live host.