How to Use dnf: The Package Manager for AlmaLinux & Rocky Linux

dnf is the package manager on AlmaLinux, Rocky Linux and the rest of the RHEL family — what apt is to Ubuntu and Debian. This guide covers the commands you will use every week, the extra repositories most servers need, automatic security updates, and how to roll back a change that went wrong.

Updating the System

sudo dnf upgrade --refresh

dnf refreshes repository metadata and installs updates in one step; there is no separate “update the list” command as with apt. (dnf update is an alias for dnf upgrade.) To see what would change first:

dnf check-update
sudo dnf upgrade --security    # security fixes only

After a kernel or core-library update, check whether a reboot is needed:

sudo dnf needs-restarting -r

Installing, Removing, Finding

sudo dnf install nginx
sudo dnf install nginx mariadb-server php-fpm
sudo dnf remove nginx
dnf search nginx
dnf info nginx
dnf provides /usr/sbin/nginx     # which package owns a file
dnf provides '*/semanage'        # which package would provide a command

Leave out -y while you are learning: dnf shows exactly what it is about to install or remove, and that list is worth reading.

Listing What Is Installed

dnf list --installed
dnf list --installed | grep php
rpm -qa --last | head        # most recently installed packages

Cleaning Up

sudo dnf autoremove     # dependencies nothing needs any more
sudo dnf clean all      # cached metadata and packages

Repositories: CRB and EPEL

Many common tools (Lynis, Fail2Ban, htop, certbot plugins) live in EPEL, the Extra Packages for Enterprise Linux. EPEL depends on the CRB repository, which is disabled by default:

sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --set-enabled crb
sudo dnf install -y epel-release
dnf repolist

Add a third-party repository from its own .repo file, and only from projects you trust:

sudo dnf config-manager --add-repo https://example.com/example.repo

Specific Versions, Downgrades and Version Locks

dnf list --showduplicates nginx      # versions available
sudo dnf install nginx-1.26.3        # a specific version
sudo dnf downgrade nginx             # back to the previous version
sudo dnf install -y python3-dnf-plugin-versionlock
sudo dnf versionlock add nginx       # stop it being upgraded

Modules (AlmaLinux and Rocky 9)

On version 9, some software comes in several streams — for example different PHP or Node.js versions:

dnf module list php
sudo dnf module reset php
sudo dnf module enable php:8.2
sudo dnf install php-fpm

Version 10 dropped modules; there, different versions arrive as separately named packages or from vendor repositories.

Package Groups

dnf group list
sudo dnf group install "Development Tools"

History and Undo

dnf records every transaction, which makes it easy to see what changed and to reverse it:

sudo dnf history
sudo dnf history info 15
sudo dnf history undo 15
sudo dnf history undo last

Undo is not a substitute for backups: it reverses package changes, not configuration or data.

Automatic Security Updates

sudo dnf install -y dnf-automatic
sudo nano /etc/dnf/automatic.conf
[commands]
upgrade_type = security
apply_updates = yes
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers | grep dnf

Automatic updates do not reboot. Check dnf needs-restarting -r from time to time, or schedule reboots in a maintenance window.

apt and dnf Side by Side

Taskapt (Ubuntu/Debian)dnf (AlmaLinux/Rocky)
Update everythingapt update && apt upgradednf upgrade --refresh
Install / removeapt install / apt removednf install / dnf remove
Searchapt searchdnf search
Which package owns a filedpkg -Sdnf provides
Hold a versionapt-mark holddnf versionlock add
Undo a change(manual)dnf history undo
Clean cacheapt cleandnf clean all

Common Problems

“No match for argument” — the package is in a repository you have not enabled (often EPEL or CRB), or the name differs. Try dnf provides '*/COMMAND'.

“Nothing provides ... needed by ...” — usually EPEL is enabled without CRB, or a third-party repository was built for another release.

Conflicting packages — sudo dnf install PACKAGE --allowerasing lets dnf replace the conflicting package. Read what it plans to remove before confirming.

dnf is slow — add max_parallel_downloads=10 and fastestmirror=True to the [main] section of /etc/dnf/dnf.conf.

Continue Reading

Browse more articles in AlmaLinux & Rocky Linux.

  • dnf, almalinux package manager, rocky linux dnf, epel repository
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

AlmaLinux vs Rocky Linux vs CentOS: What Happened to CentOS?

If you're choosing a RHEL-compatible Linux distribution for your VPS, understanding the CentOS...

How to Get Started with AlmaLinux/Rocky Linux on a VPS

This guide covers the essential first steps after deploying a new AlmaLinux or Rocky Linux VPS...

How to Configure firewalld on AlmaLinux/Rocky Linux

firewalld is the default firewall management tool on AlmaLinux and Rocky Linux, using a...

How to Install Nginx on AlmaLinux/Rocky Linux

This guide covers installing and configuring Nginx on AlmaLinux or Rocky Linux, including the...

How to Install Apache (httpd) on AlmaLinux/Rocky Linux

On RHEL-family distributions, Apache is packaged as httpd rather than apache2 — a naming...