CloudsArk
Commands Linux

What Is the dnf Command in Linux?

Learn what the dnf command does in Linux, how its syntax works, and when to use it.

What Is the dnf Command in Linux?

Introduction

The dnf command installs, removes, updates, and queries packages on RHEL-style systems. It is useful for beginners, Linux administrators, DevOps engineers, and RHCSA students because it solves practical terminal tasks.

What the Command Does

Use dnf to work with the specific Linux object it manages. Before changing anything, identify the target and run a read-only check when possible.

Basic Syntax

dnf COMMAND PACKAGE

The syntax includes the command, any options, and the target object.

Common Options

  • install: install packages.
  • remove: remove packages.
  • history: show transaction history.

Practical Examples

sudo dnf install httpd
sudo dnf update
dnf search nginx
sudo dnf remove httpd

Verification command:

dnf list installed httpd

Example output:

Installed Packages
httpd.x86_64    2.4.57-11.el9    @appstream

When to Use This Command

Use dnf on RHEL, Rocky Linux, AlmaLinux, and Fedora systems to manage RPM packages and repositories. On newer systems, yum often works as a compatibility wrapper for dnf.

Common Mistakes

  • Running updates on production systems without a change window.
  • Ignoring repository or subscription errors.
  • Removing a package without checking dependent services.

Quick Reference

sudo dnf install httpd
sudo dnf update
dnf list installed httpd

Summary

The dnf command is safest when you understand the target, choose the right option, and verify the result with a separate command.