dnf / yum (Fedora & RHEL)
dnf (and its predecessor yum) manage packages on Red Hat based systems.
Syntax
sudo 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
| Task | apt | dnf |
|---|---|---|
| Install | apt install | dnf install |
| Remove | apt remove | dnf remove |
| Update all | apt upgrade | dnf upgrade |
| Search | apt search | dnf search |
One nice difference: dnf refreshes its metadata automatically, so there is no separate update step before installing.
Example
# 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 gitWhen 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.
# Install a package (Fedora/RHEL/CentOS)
sudo dnf install nginx
# Update all packages
sudo dnf upgrade -y
# Update a single package
sudo dnf upgrade nginxSearch and remove packages
Demonstrates the search, info, and remove workflow in dnf which behaves similarly to apt.
# Search for a package
dnf search postgresql
# Show package information
dnf info nginx
# Remove a package and its unused dependencies
sudo dnf remove nginxManage repositories
Shows how to add third-party repositories and install packages from them on RHEL-family systems.
# 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