Skip to main content

Package Manager

A Linux package manager installs, updates, and removes software and automatically handles its dependencies. apt manages .deb packages on Debian and Ubuntu, while dnf and yum manage .rpm packages on RHEL-family systems.

Understanding Linux Package Managers

What Is a Package Manager in Linux?

A package manager replaces the manual cycle of downloading, compiling, and copying files into place. It reads a repository index, works out which dependencies are needed (nginx needs OpenSSL, for example), downloads signed packages, verifies them, and records what it installed so it can be updated or removed cleanly.

flowchart TD A[apt install nginx] --> B[Read local package index] B --> C[Resolve dependencies] C --> D[Download and verify signatures] D --> E[Install files and register service]

Debian and Ubuntu: apt and dpkg

Bash
sudo apt update # refresh the index (installs nothing)
sudo apt install nginx
sudo apt install nginx=1.24.0-1ubuntu1 # specific version
sudo apt remove nginx # keep config
sudo apt purge nginx # remove config too
sudo apt upgrade
apt search nginx
apt show nginx
apt-cache policy nginx # which repo and version
dpkg -l | grep nginx # installed packages
dpkg -S /usr/sbin/nginx # which package owns a file
dpkg -L nginx # files in a package
sudo apt-mark hold nginx # block upgrades
apt-mark showhold

RHEL, Fedora, and Amazon Linux: dnf and rpm

Bash
sudo dnf install nginx # yum on older systems
sudo dnf remove nginx
sudo dnf upgrade
dnf search nginx
dnf info nginx
rpm -qa | grep nginx
rpm -ql nginx # files in a package
rpm -qf /usr/sbin/nginx # which package owns a file

Troubleshooting Package Managers

Symptom Command What to Check
Package not found sudo apt update Stale index
Wrong version apt-cache policy pkg Which repo wins
Dependency conflict sudo apt install -f Broken dependencies
GPG error on new repo Import vendor key Signing key missing
Remember

apt update only refreshes the list of available packages. It does not upgrade anything. Run it before apt install so you do not install stale versions.

Security

Add third-party repositories only from trusted vendors and verify the signing key fingerprint against the vendor's official site. A malicious repository can replace system binaries.

Common Mistake

Running a blanket apt upgrade on production. It pulls whatever is newest at that moment. Pin critical packages, test in staging, and use a mirrored repository for reproducible builds.

Frequently Asked Questions

How do apt and dnf differ?

apt works with .deb packages on Debian and Ubuntu, dnf works with .rpm packages on RHEL, Fedora, and Amazon Linux 2023. Both resolve dependencies and verify signatures, but formats, repository metadata, and commands differ and are not interchangeable.

Why does apt install sometimes get an old version?

The local package index may be stale, so run `apt update` first. Also check `apt-cache policy` to see which repository is providing the version.

How do I stop a package from being upgraded?

On Debian and Ubuntu use `apt-mark hold package`. On RHEL-family systems use the versionlock plugin for dnf.

Found a mistake, an outdated step or a broken link?