Package Managers: apt and yum

beginner
10 min

Package Managers: apt and yum

Installing software on Linux is very different from downloading installers on Windows or macOS. Instead, almost every distribution ships with a package manager: a tool that downloads software from trusted online repositories, resolves dependencies automatically, and keeps everything up to date with a single command. In this lesson you will learn the two most common families of package managers: apt, used by Debian and Ubuntu, and yum/dnf, used by Red Hat, CentOS, Fedora and Amazon Linux.

What Is a Package Manager?

A package is a compressed archive containing a program, its configuration files, and metadata describing what other packages it needs. The package manager reads that metadata and installs every dependency for you. This solves the classic problem of hunting down libraries by hand. Packages come from repositories, which are servers maintained by your distribution. Because repositories are cryptographically signed, you also get a strong security guarantee that the software has not been tampered with.

Installing Software with apt

On Debian-based systems such as Ubuntu, the tool is apt. Before installing anything, refresh the local index of available packages, then install what you need:

bash
sudo apt update # refresh the package index sudo apt install htop # install a package sudo apt upgrade # upgrade all installed packages sudo apt remove htop # uninstall but keep config files sudo apt purge htop # uninstall and delete config files apt search monitor # search the repositories apt show htop # view details about a package

Notice that read-only commands like search do not need sudo, while anything that changes the system does. Run apt update regularly; the index is only a snapshot, and installing from a stale index can fail with 404 errors.

Managing Packages with yum and dnf

Red Hat-based distributions use yum, or its modern successor dnf, which accepts the same syntax. The commands map almost one-to-one to apt:

bash
sudo yum check-update # see what can be upgraded sudo yum install htop # install a package sudo yum update # upgrade everything sudo yum remove htop # uninstall a package yum search monitor # search repositories yum info htop # show package details

One practical difference: yum refreshes its metadata automatically when needed, so there is no separate mandatory update step before installing.

Cleaning Up and Fixing Problems

Over time, downloaded package archives and orphaned dependencies accumulate. Both ecosystems provide housekeeping commands:

bash
sudo apt autoremove # remove unused dependencies (Debian/Ubuntu) sudo apt clean # clear the download cache sudo yum autoremove # same idea on Red Hat systems sudo yum clean all

If an apt operation is interrupted, you may see a locked database error. Wait for any running unattended upgrade to finish, then run sudo dpkg --configure -a to repair a half-finished installation.

Which One Should You Learn?

Learn the one your servers actually run, but understand both. In cloud environments you will constantly bounce between Ubuntu images (apt) and Amazon Linux images (yum/dnf). The mental model is identical: update the index, install, upgrade, remove, clean. Once you know one, the other takes minutes to pick up. Avoid mixing in software installed manually from source when a package exists, because manual installs are invisible to the package manager and will not receive security updates.

Key Takeaways

  • Package managers install software plus all of its dependencies from signed repositories.
  • Debian and Ubuntu use apt; Red Hat, CentOS and Fedora use yum or dnf.
  • Run sudo apt update before installing on Debian-based systems.
  • Use remove or purge to uninstall, and autoremove to clear unused dependencies.
  • Prefer packaged software over manual installs so you keep getting security updates.

In the next lesson, we will look at environment variables and the .bashrc file, and see how to customize your shell so it behaves exactly the way you want.