Linux VPS

Linux package managers explained: apt, dnf and yum

Install, update, search and remove software on Ubuntu, Debian, AlmaLinux and Rocky Linux with apt, dnf and yum, with side-by-side command examples.

BeginnerLinux VPS2 min read

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

Which package manager does my server use

DistributionPackage managerPackage format
Ubuntu, Debianapt.deb
AlmaLinux, Rocky Linux, CloudLinux 8/9dnf (yum works as an alias).rpm
CentOS 7, CloudLinux 7yum.rpm

Update the package list and upgrade

On Ubuntu and Debian, refresh the package index first, then upgrade:

sudo apt update
sudo apt upgrade -y

On AlmaLinux and Rocky Linux, dnf refreshes metadata automatically:

sudo dnf upgrade -y

Tip: 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 htop
dnf search htop
sudo dnf install htop

Many extra packages on AlmaLinux and Rocky Linux live in the EPEL repository. Enable it once:

sudo dnf install epel-release

Remove a package

sudo apt remove htop
sudo apt autoremove
sudo dnf remove htop

apt purge also deletes the package's configuration files; autoremove clears dependencies nothing needs any more.

See what is installed

apt list --installed | grep nginx
dnf list installed | grep nginx

To find which package owns a file, use dpkg -S /usr/bin/htop (apt) or rpm -qf /usr/bin/htop (dnf).

Quick command comparison

Taskaptdnf / yum
Refresh indexapt updatednf makecache
Upgrade allapt upgradednf upgrade
Installapt install pkgdnf install pkg
Removeapt remove pkgdnf remove pkg
Searchapt search worddnf search word
Package infoapt show pkgdnf info pkg
History and undo/var/log/apt/history.logdnf 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.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.