dnf / yum (Fedora & RHEL)

dnf (and its predecessor yum) manage packages on Red Hat based systems.

Syntaxsudo dnf [install|remove|upgrade|search] [package]

On Fedora, RHEL, CentOS and Rocky Linux the package manager is dnf (older systems use yum, which takes the same commands). It does the same job as apt, just with different names.

Equivalent commands

Taskaptdnf
Installapt installdnf install
Removeapt removednf remove
Update allapt upgradednf upgrade
Searchapt searchdnf search

One nice difference: dnf refreshes its metadata automatically, so there is no separate update step before installing.

Example

Example Β· bash
# Install a package
sudo dnf install git

# Update everything
sudo dnf upgrade

# Search for a package
dnf search nginx

# Remove a package
sudo dnf remove git

When to use it

  • A sysadmin installs Apache on a RHEL server with 'sudo dnf install httpd' using the Red Hat package manager.
  • A DevOps engineer adds the EPEL repository with 'sudo dnf install epel-release' to access extra packages not in the base RHEL repos.
  • A security team runs 'sudo dnf check-update --security' to list only security-relevant updates before applying them.

More examples

Install and update with dnf

Shows the dnf equivalents of apt install and apt upgrade for Red Hat family distributions.

Example Β· bash
# Install a package (Fedora/RHEL/CentOS)
sudo dnf install nginx

# Update all packages
sudo dnf upgrade -y

# Update a single package
sudo dnf upgrade nginx

Search and remove packages

Demonstrates the search, info, and remove workflow in dnf which behaves similarly to apt.

Example Β· bash
# Search for a package
dnf search postgresql

# Show package information
dnf info nginx

# Remove a package and its unused dependencies
sudo dnf remove nginx

Manage repositories

Shows how to add third-party repositories and install packages from them on RHEL-family systems.

Example Β· bash
# Add EPEL repository for extra packages
sudo dnf install epel-release

# List all enabled repositories
dnf repolist

# Install from a specific repo
sudo dnf install --enablerepo=epel htop

Discussion

  • Be the first to comment on this lesson.
dnf / yum (Fedora & RHEL) β€” Linux | SoundsCode