Package Management Commands
apt, yum/dnf, rpm, and dpkg — installing, updating, removing, and querying software packages across Debian- and Red Hat-based distros.
Two Major Families
apt/dnf are high-level tools that resolve dependencies automatically and fetch from remote repositories. dpkg/rpm are low-level tools that install a single package file directly — you handle dependencies yourself.
Debian / Ubuntu: apt
sudo apt update # refresh the package index (does NOT install/upgrade anything)
sudo apt upgrade # upgrade all installed packages to latest versions
sudo apt install nginx # install a package (+ dependencies)
sudo apt remove nginx # remove a package, keep its config files
sudo apt purge nginx # remove a package AND its config files
sudo apt autoremove # remove orphaned dependencies no longer needed
apt search nginx # search available packages
apt show nginx # detailed info about a package
apt list --installed | grep nginx # check if/which version is installed
dpkg -i package.deb # install a local .deb file directly
dpkg -L nginx # list files installed by a package
dpkg -S /etc/nginx/nginx.conf # which package owns this file?
RHEL / CentOS / Amazon Linux / Fedora: dnf (or yum)
sudo dnf update # update all packages (yum equivalent: yum update)
sudo dnf install nginx # install a package
sudo dnf remove nginx # remove a package
sudo dnf search nginx # search available packages
sudo dnf info nginx # detailed package info
sudo dnf list installed | grep nginx # check installed version
sudo dnf history # log of past transactions
sudo dnf history undo <id> # roll back a specific transaction
rpm -qa | grep nginx # query all installed packages, filter by name
rpm -ql nginx # list files installed by a package
rpm -qf /etc/nginx/nginx.conf # which package owns this file?
rpm -ivh package.rpm # install a local .rpm file directly
Repository Management
# Debian/Ubuntu
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/
sudo add-apt-repository ppa:some/ppa
# RHEL/CentOS
ls /etc/yum.repos.d/
sudo dnf config-manager --add-repo <url>
Checking for Available Updates (Without Installing)
apt list --upgradable # Debian/Ubuntu: what WOULD be upgraded
sudo dnf check-update # RHEL/Fedora: same idea
Production Considerations
- Always run
apt updatebeforeapt install/apt upgradeon a fresh session — an install can otherwise fail silently against a stale package index. dnf history undois a genuine safety net after a bad update on RHEL-family systems — there’s no exact equivalent inapt, making pre-upgrade snapshots more important on Debian-family hosts.- Pin critical package versions (
apt-mark hold <pkg>/dnf versionlock) for production systems where an unplanned major-version bump (e.g., a database engine) could break compatibility.
Quick Interview Answer
“Debian-based distros use
apt(high-level, dependency-resolving) on top ofdpkg(low-level, single-package installs); Red Hat-based distros usednf/yumon top ofrpmthe same way.apt updaterefreshes the package index,apt upgradeactually upgrades packages — they’re often confused but do very different things.dnf history undogives RHEL-family systems a built-in rollback that apt doesn’t have natively.”
Common Mistakes
- Confusing
apt update(refresh index) withapt upgrade(actually upgrade packages) — a very common beginner mix-up. - Installing a
.deb/.rpmdirectly withdpkg -i/rpm -ivhand then being surprised dependencies aren’t resolved automatically. - Not pinning/holding critical package versions before a routine
apt upgrade/dnf updateon a production server.
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form