Skip to main content

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

◈ DIAGRAM
+------------------------------------------+
| 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

Bash
## ── Debian/Ubuntu (apt) ──────────────────────────────────
## Update package index (must run before installing)
sudo apt update
## Install package
sudo apt install nginx
## Install specific version
sudo apt install nginx=1.24.0-1ubuntu1
## Remove package (keep config)
sudo apt remove nginx
## Remove package and config files
sudo apt purge nginx
## Upgrade all packages
sudo apt upgrade
## Search for a package
apt search nginx
apt-cache show nginx ## show package details
## List installed packages
dpkg -l
dpkg -l | grep nginx
## Find which package owns a file
dpkg -S /usr/sbin/nginx
## nginx: /usr/sbin/nginx
## List files installed by a package
dpkg -L nginx
## Pin a package version (prevent auto-upgrade)
sudo apt-mark hold nginx
sudo apt-mark showhold ## list held packages
## ── RHEL/Amazon Linux (yum/dnf) ──────────────────────────
sudo yum install nginx ## or dnf install nginx
sudo yum remove nginx
sudo yum update
yum search nginx
yum info nginx
rpm -qa | grep nginx ## list installed RPM packages
rpm -ql nginx ## list files in package
rpm -qf /usr/sbin/nginx ## which package owns this file

Troubleshooting

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 update updates the local index of available packages — it does NOT install or upgrade anything. It must be run before apt install to ensure you get current package versions. Forgetting this is why servers end up with outdated versions installed.

Security

Only 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.