CloudsArk
Commands Linux

dnf Command Examples in Linux

Practice useful dnf command examples for everyday Linux administration and troubleshooting.

dnf Command Examples in Linux

Introduction

These examples show practical ways to use dnf on a Linux terminal. Each example is written so you can adapt it for administration or troubleshooting.

Example 1: Basic Usage

sudo dnf install httpd

This is the simplest form of the command and is a good starting point before adding options.

Example 2: Common Admin Task

sudo dnf update

This example reflects a common task on RHEL, Rocky Linux, AlmaLinux, or similar systems.

Example 3: Useful Option

dnf search nginx

This option helps narrow the result, change behavior, or handle a more realistic target.

Example 4: Real-World Scenario

sudo dnf remove httpd

Use this pattern when the task moves beyond a single basic command.

Example 5: Verification

dnf list installed httpd

Example output:

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

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 search nginx
sudo dnf remove httpd
dnf list installed httpd

Summary

Good dnf usage means choosing the right option, keeping the target clear, and verifying the result with output you can explain.