Package Management: Installing, Updating, and Removing with apt / yum / dnf
Install software, patch the system, and clean up cruft with a single command—once you know which distro family your server belongs to.
On a Linux server you don't download installers from a website. Instead, a package manager pulls software over the network from official repositories. All you really need to know is your server's family: Debian / Ubuntu use apt, while RHEL / CentOS / Rocky / AlmaLinux / Fedora use dnf (older systems call it yum, and the commands are nearly identical).
Check your distribution first:
cat /etc/os-release
Most commands below need admin rights, so prefix them with sudo (you can drop it if you're already root).
Debian / Ubuntu: apt
sudo apt update # refresh the package index (nothing gets upgraded)
sudo apt upgrade # upgrade every package that has a newer version
sudo apt install nginx # install a package
sudo apt remove nginx # uninstall (keeps config files)
sudo apt purge nginx # uninstall and delete config files too
sudo apt search keyword # search for a package
sudo apt autoremove # drop dependencies no longer needed
sudo apt clean # empty the downloaded-package cache
In apt, update and upgrade are two different things: update only refreshes the "catalog," while upgrade actually installs newer versions. The everyday habit is to chain them: sudo apt update && sudo apt upgrade.
RHEL family: dnf / yum
sudo dnf check-update # see what has updates available
sudo dnf upgrade # upgrade everything
sudo dnf install nginx # install a package
sudo dnf remove nginx # uninstall
sudo dnf search keyword # search for a package
sudo dnf autoremove # remove orphaned dependencies
sudo dnf clean all # clear the cache
If your server is old enough to have only yum, just swap dnf for yum—the behavior is virtually the same. There's no separate "refresh the index" step here; dnf checks for updates on its own when needed.
Quick comparison
| Task | apt (Debian/Ubuntu) | dnf (RHEL family) | |---|---|---| | Refresh index | apt update | (automatic) | | Upgrade all | apt upgrade | dnf upgrade | | Install | apt install <pkg> | dnf install <pkg> | | Remove | apt remove <pkg> | dnf remove <pkg> | | Search | apt search <term> | dnf search <term> | | Clean cache | apt clean | dnf clean all |
About repositories
Behind every package manager sits a list of repositories that tells it where to fetch software. For apt, that lives in /etc/apt/sources.list and /etc/apt/sources.list.d/; for dnf, in /etc/yum.repos.d/. The bundled official repos cover most needs. If a package simply can't be found, you may need to add a third-party repository per the vendor's docs. And if the official repos feel slow from your region, switching to a nearby mirror can speed things up.
Summary
Before installing anything, run os-release to spot your family: Debian/Ubuntu use apt, the RHEL side uses dnf (or yum). Learn the three verbs install / remove / search, remember that apt needs an update before an upgrade, and upgrade regularly while running autoremove + clean to keep the server both current and tidy.