Linux Basics · Lesson 11 · 20 min

Installing software: dnf vs apt

This is the biggest everyday difference between the two families. Once you've got it, you can follow almost any tutorial on either one.

You will learn

  • What packages, repositories and package managers are
  • Installing, searching, updating and removing software with dnf and with apt
  • Why Ubuntu needs apt update and why Rocky needs EPEL
  • Detective work: which package gives me this command, and which package does this file belong to?

The app store idea

On a phone you install apps from an app store. Linux had the same idea years earlier:

Changing software changes the whole system, so these commands need sudo (lesson 12 explains why).

Install your first package

Rocky / RHEL
sudo dnf install tree

dnf refreshes its list of available software by itself. It asks Is this ok [y/N]. The capital N means pressing Enter answers no, so type y.

Ubuntu / Debian
sudo apt update
sudo apt install tree

First apt update refreshes the list of what's available (it doesn't install anything!), then apt install. When apt asks [Y/n], pressing Enter means yes.

Add -y on either one to answer yes automatically: sudo dnf install -y tree or sudo apt install -y tree.

The full comparison

I want to…Rocky / RHELUbuntu / Debian
Refresh the list of available softwareautomatic (or dnf check-update)sudo apt update
Install somethingsudo dnf install NAMEsudo apt install NAME
Remove somethingsudo dnf remove NAMEsudo apt remove NAME
Update everythingsudo dnf upgradesudo apt update && sudo apt upgrade
Search for softwarednf search WORDapt search WORD
Details about a packagednf info NAMEapt show NAME
List what's installeddnf list installed or rpm -qaapt list --installed or dpkg -l
See the repositoriesdnf repolistapt policy
Old name you'll see in tutorialsyum (still works, it's just dnf)apt-get (still works)
Extra software repoEPEL: sudo dnf install epel-release“universe”, already switched on

Package detective work

Two questions come up constantly: “which package do I install to get the dig command?” and “which package did this file come from?”

QuestionRocky / RHELUbuntu / Debian
Which package provides a command?dnf provides '*/bin/dig'apt-file search bin/dig (install apt-file), or just run the command: Ubuntu suggests the package
Which package owns this file?rpm -qf /usr/bin/lsdpkg -S /usr/bin/ls
Search (the older tool)dnf search WORDapt-cache search WORD
Which version would install, and from where?dnf info NAMEapt-cache policy NAME
What does it depend on?dnf deplist NAMEapt-cache depends NAME

apt-cache is the older sibling of apt. Scripts and tutorials still use it because its output doesn't change between versions, and apt even warns that its own output isn't meant for scripts.

What does && do?

A && B means “run A, and if it worked, run B.” That's why sudo apt update && sudo apt upgrade is one of the most-typed lines on Ubuntu.

EPEL: Rocky's bonus shelf

The RHEL family keeps its official repos small and carefully tested. That's great for stability, but some fun or niche tools (like cowsay, htop and sl) aren't in them. They live in EPEL (Extra Packages for Enterprise Linux), a well-known community repo. You switch it on by installing one package:

Rocky / RHEL
sudo dnf install epel-release
sudo dnf install cowsay

Some EPEL packages also need the CRB repo: sudo dnf config-manager --set-enabled crb

Ubuntu / Debian
sudo apt install cowsay

Ubuntu's “universe” repo is huge and already switched on, so there's nothing extra to set up.

Heads up: same software, different names

Sometimes the same program has a different package name in each family. The most famous one: the Apache web server is httpd on Rocky and apache2 on Ubuntu. When an install says “not found,” this is often why. You'll use it in lesson 14.

Try it

Do the missions on one family, then click the other family's button in the terminal bar and do them again. Notice where each one trips you up.

Quick check

1. On Ubuntu, what does sudo apt update do?

2. sudo dnf install htop says “No match for argument.” What's the most likely fix on Rocky?

3. dnf asks Is this ok [y/N]: and you just press Enter. What happens?

Finished the missions and the quiz? Mark it done to track your progress.