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.
Debian and Ubuntu: apt and dpkg
sudo apt update # refresh the index (installs nothing)sudo apt install nginxsudo apt install nginx=1.24.0-1ubuntu1 # specific versionsudo apt remove nginx # keep configsudo apt purge nginx # remove config toosudo apt upgrade apt search nginxapt show nginxapt-cache policy nginx # which repo and version dpkg -l | grep nginx # installed packagesdpkg -S /usr/sbin/nginx # which package owns a filedpkg -L nginx # files in a package sudo apt-mark hold nginx # block upgradesapt-mark showholdRHEL, Fedora, and Amazon Linux: dnf and rpm
sudo dnf install nginx # yum on older systemssudo dnf remove nginxsudo dnf upgradednf search nginxdnf info nginxrpm -qa | grep nginxrpm -ql nginx # files in a packagerpm -qf /usr/sbin/nginx # which package owns a fileTroubleshooting 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 updateonly refreshes the list of available packages. It does not upgrade anything. Run it beforeapt installso you do not install stale versions.
SecurityAdd 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 MistakeRunning a blanket
apt upgradeon 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.