Every Linux distribution installs software through a package manager that downloads packages from trusted repositories, resolves dependencies and keeps everything updatable. Ubuntu and Debian use apt; AlmaLinux, Rocky Linux and CloudLinux use dnf, with yum kept as a compatible alias. This guide shows the commands you will use daily on both families.
Before you start
- A Linux VPS and an SSH session (see connect to a Linux VPS with SSH).
- A user with sudo rights (see create a sudo user).
- Not sure which distro you run? See check your Linux version.
Which package manager does my server use
| Distribution | Package manager | Package format |
|---|---|---|
| Ubuntu, Debian | apt | .deb |
| AlmaLinux, Rocky Linux, CloudLinux 8/9 | dnf (yum works as an alias) | .rpm |
| CentOS 7, CloudLinux 7 | yum | .rpm |
Update the package list and upgrade
On Ubuntu and Debian, refresh the package index first, then upgrade:
sudo apt update
sudo apt upgrade -yOn AlmaLinux and Rocky Linux, dnf refreshes metadata automatically:
sudo dnf upgrade -yTip: Run updates before installing new software on a fresh VPS. To patch automatically, follow automatic security updates.
Search for and install a package
apt search htop
sudo apt install htopdnf search htop
sudo dnf install htopMany extra packages on AlmaLinux and Rocky Linux live in the EPEL repository. Enable it once:
sudo dnf install epel-releaseRemove a package
sudo apt remove htop
sudo apt autoremovesudo dnf remove htopapt purge also deletes the package's configuration files; autoremove clears dependencies nothing needs any more.
See what is installed
apt list --installed | grep nginxdnf list installed | grep nginxTo find which package owns a file, use dpkg -S /usr/bin/htop (apt) or rpm -qf /usr/bin/htop (dnf).
Quick command comparison
| Task | apt | dnf / yum |
|---|---|---|
| Refresh index | apt update | dnf makecache |
| Upgrade all | apt upgrade | dnf upgrade |
| Install | apt install pkg | dnf install pkg |
| Remove | apt remove pkg | dnf remove pkg |
| Search | apt search word | dnf search word |
| Package info | apt show pkg | dnf info pkg |
| History and undo | /var/log/apt/history.log | dnf history, dnf history undo ID |
Troubleshooting
- Could not get lock /var/lib/dpkg/lock: another apt process (often unattended-upgrades) is running. Wait a few minutes; never delete the lock file while it runs.
- No match for argument on dnf: the package is in another repository (often EPEL) or has another name; try
dnf provides '*/command'. - Packages kept back on apt: review and run
sudo apt full-upgrade. - No space left on device: see free up disk space on Linux.
