DNF Package Manager: Complete Guide for Fedora/RHEL 8+

Master DNF package manager with this comprehensive guide covering installation, configuration, commands, and best practices for Fedora and RHEL 8+.

DNF Package Manager: Complete Guide for Fedora/RHEL 8+

Table of Contents

1. [Introduction](#introduction) 2. [Basic Concepts](#basic-concepts) 3. [Installation and Configuration](#installation-and-configuration) 4. [Core Commands](#core-commands) 5. [Package Management Operations](#package-management-operations) 6. [Repository Management](#repository-management) 7. [Advanced Features](#advanced-features) 8. [Configuration Files](#configuration-files) 9. [Troubleshooting](#troubleshooting) 10. [Best Practices](#best-practices)

Introduction

DNF (Dandified YUM) is the next-generation package manager for RPM-based Linux distributions, serving as the default package manager for Fedora 22+ and Red Hat Enterprise Linux 8+. It replaced YUM (Yellowdog Updater Modified) with improved performance, better dependency resolution, and enhanced features.

DNF handles the installation, removal, and management of software packages in RPM format. It automatically resolves dependencies, manages repositories, and provides a robust command-line interface for system administration tasks.

Key Features

- Improved Performance: Faster metadata processing and package operations - Better Dependency Resolution: Advanced SAT solver for complex dependency scenarios - Memory Efficiency: Lower memory footprint compared to YUM - Plugin Architecture: Extensible through plugins - Transaction History: Complete tracking of package operations - Modular Content Support: Support for application streams and modules

Basic Concepts

Package Management Terminology

| Term | Description | |------|-------------| | Package | A compiled software bundle containing executables, configuration files, and metadata | | Repository | A collection of packages stored on a server or local storage | | Metadata | Information about packages including dependencies, descriptions, and versions | | Transaction | A set of package operations performed atomically | | Group | A collection of related packages that can be installed together | | Module | A set of RPM packages representing an application, language runtime, or database |

Package States

| State | Description | |-------|-------------| | Available | Package exists in configured repositories but not installed | | Installed | Package is currently installed on the system | | Upgradeable | Newer version available in repositories | | Obsoleted | Package replaced by another package | | Broken | Package has unresolved dependencies |

Installation and Configuration

Installing DNF

DNF comes pre-installed on Fedora 22+ and RHEL 8+. For older systems or minimal installations:

`bash

On RHEL/CentOS 8

sudo yum install dnf

On Fedora (if somehow missing)

sudo yum install dnf `

Initial Setup

After installation, update the package database:

`bash sudo dnf makecache `

This command downloads and caches repository metadata for faster subsequent operations.

Core Commands

Basic Syntax

`bash dnf [options] [arguments] `

Essential Commands Reference

| Command | Purpose | Example | |---------|---------|---------| | install | Install packages | dnf install firefox | | remove | Remove packages | dnf remove firefox | | update | Update packages | dnf update | | search | Search for packages | dnf search editor | | info | Display package information | dnf info vim | | list | List packages | dnf list installed | | check-update | Check for updates | dnf check-update | | clean | Clean cache | dnf clean all |

Command Options

| Option | Description | Example | |--------|-------------|---------| | -y, --assumeyes | Automatically answer yes to prompts | dnf -y install package | | -q, --quiet | Quiet operation | dnf -q list | | -v, --verbose | Verbose output | dnf -v install package | | --nogpgcheck | Skip GPG signature verification | dnf --nogpgcheck install package | | --downloadonly | Download packages without installing | dnf --downloadonly install package | | --enablerepo | Enable specific repository | dnf --enablerepo=repo install package | | --disablerepo | Disable specific repository | dnf --disablerepo=repo install package |

Package Management Operations

Installing Packages

#### Single Package Installation `bash

Install a single package

sudo dnf install vim

Install with automatic confirmation

sudo dnf -y install git

Install specific version

sudo dnf install vim-8.2.1234 `

#### Multiple Package Installation `bash

Install multiple packages

sudo dnf install vim git curl wget

Install from local RPM file

sudo dnf install /path/to/package.rpm

Install from URL

sudo dnf install https://example.com/package.rpm `

#### Conditional Installation `bash

Install only if not already installed

sudo dnf install --skip-broken package-name

Install with best candidate selection

sudo dnf install --best package-name `

Removing Packages

#### Basic Removal `bash

Remove single package

sudo dnf remove firefox

Remove multiple packages

sudo dnf remove firefox thunderbird

Remove with dependencies (autoremove)

sudo dnf autoremove firefox `

#### Advanced Removal Options `bash

Remove packages and unused dependencies

sudo dnf remove firefox && sudo dnf autoremove

Remove all packages matching pattern

sudo dnf remove "firefox"

Simulate removal (dry run)

sudo dnf remove --assumeno firefox `

Updating Packages

#### System Updates `bash

Update all packages

sudo dnf update

Update with automatic confirmation

sudo dnf -y update

Check for available updates

sudo dnf check-update `

#### Selective Updates `bash

Update specific package

sudo dnf update firefox

Update packages from specific repository

sudo dnf --enablerepo=updates update

Update security patches only

sudo dnf --security update `

#### Update Exclusions `bash

Exclude specific packages from update

sudo dnf update --exclude=kernel*

Update everything except specific packages

sudo dnf update -x kernel -x firefox `

Searching and Querying Packages

#### Search Operations `bash

Search by package name

dnf search firefox

Search in package descriptions

dnf search --all "text editor"

Search for files provided by packages

dnf provides /usr/bin/vim `

#### Package Information `bash

Display detailed package information

dnf info firefox

Show package dependencies

dnf repoquery --requires firefox

Show what packages depend on this package

dnf repoquery --whatrequires firefox

List files in package

dnf repoquery --list firefox `

#### Listing Packages `bash

List all installed packages

dnf list installed

List available packages

dnf list available

List upgradeable packages

dnf list upgrades

List packages by pattern

dnf list "firefox" `

Package Groups

#### Group Operations `bash

List available groups

dnf group list

Install package group

sudo dnf group install "Development Tools"

Remove package group

sudo dnf group remove "Development Tools"

Show group information

dnf group info "Development Tools" `

#### Group Management Examples

| Group Name | Description | Install Command | |------------|-------------|-----------------| | "Development Tools" | Compilers and development utilities | dnf group install "Development Tools" | | "System Tools" | System administration tools | dnf group install "System Tools" | | "Security Tools" | Security and monitoring tools | dnf group install "Security Tools" | | "Multimedia" | Audio and video applications | dnf group install "Multimedia" |

Repository Management

Repository Configuration

#### Listing Repositories `bash

List enabled repositories

dnf repolist

List all repositories (enabled and disabled)

dnf repolist --all

Show repository information

dnf repoinfo fedora `

#### Repository Operations `bash

Enable repository temporarily

sudo dnf --enablerepo=updates-testing install package

Disable repository temporarily

sudo dnf --disablerepo=updates install package

Enable repository permanently

sudo dnf config-manager --set-enabled repository-name

Disable repository permanently

sudo dnf config-manager --set-disabled repository-name `

#### Adding New Repositories `bash

Add repository from URL

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

Add RPM Fusion repositories (Fedora)

sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

Add EPEL repository (RHEL/CentOS)

sudo dnf install epel-release `

Repository Configuration Files

Repository configurations are stored in /etc/yum.repos.d/. Example repository file:

`ini [example-repo] name=Example Repository baseurl=https://example.com/repo/ enabled=1 gpgcheck=1 gpgkey=https://example.com/repo/RPM-GPG-KEY `

#### Repository Configuration Parameters

| Parameter | Description | Values | |-----------|-------------|--------| | name | Human-readable repository name | String | | baseurl | Repository URL | URL | | enabled | Enable/disable repository | 0 or 1 | | gpgcheck | Verify GPG signatures | 0 or 1 | | gpgkey | GPG key location | URL or file path | | priority | Repository priority | Number (1-99) | | includepkgs | Include only specified packages | Package patterns | | excludepkgs | Exclude specified packages | Package patterns |

Advanced Features

DNF Modules

Modules provide multiple versions of applications and runtime environments.

#### Module Operations `bash

List available modules

dnf module list

Show module information

dnf module info nodejs

Install module stream

sudo dnf module install nodejs:14

Enable module stream

sudo dnf module enable nodejs:14

Disable module

sudo dnf module disable nodejs

Reset module

sudo dnf module reset nodejs `

#### Module Management Examples

| Module | Available Streams | Default | Command | |--------|------------------|---------|---------| | nodejs | 10, 12, 14, 16 | 14 | dnf module install nodejs:16 | | python | 2.7, 3.6, 3.8, 3.9 | 3.8 | dnf module install python:3.9 | | postgresql | 9.6, 10, 11, 12, 13 | 12 | dnf module install postgresql:13 | | nginx | 1.16, 1.18, 1.20 | 1.18 | dnf module install nginx:1.20 |

Transaction History

#### History Commands `bash

Show transaction history

dnf history

Show detailed transaction information

dnf history info 5

Undo transaction

sudo dnf history undo 5

Redo transaction

sudo dnf history redo 5

Rollback to specific transaction

sudo dnf history rollback 3 `

#### History Information Table

| Column | Description | |--------|-------------| | ID | Transaction identifier | | Command Line | Original command executed | | Date and time | When transaction occurred | | Action(s) | Install, Update, Remove, etc. | | Altered | Number of packages affected |

DNF Plugins

#### Common Plugins

| Plugin | Purpose | Installation | |--------|---------|--------------| | dnf-automatic | Automatic updates | dnf install dnf-automatic | | dnf-plugins-core | Core plugin collection | Usually pre-installed | | dnf-utils | Additional utilities | dnf install dnf-utils | | needs-restarting | Check restart requirements | Part of dnf-utils |

#### Plugin Usage Examples `bash

Check which services need restart after updates

sudo needs-restarting -s

Download packages to specific directory

sudo dnf download --destdir=/tmp firefox

Show package changelog

dnf changelog firefox

Find which package owns a file

dnf provides /usr/bin/git `

Performance Optimization

#### Cache Management `bash

Clean all cache

sudo dnf clean all

Clean only metadata

sudo dnf clean metadata

Clean packages cache

sudo dnf clean packages

Make cache for faster operations

sudo dnf makecache `

#### Parallel Downloads Configure parallel downloads in /etc/dnf/dnf.conf:

`ini [main] max_parallel_downloads=10 fastestmirror=true deltarpm=true `

Configuration Files

Main Configuration File

The primary DNF configuration file is /etc/dnf/dnf.conf:

`ini [main] gpgcheck=1 installonly_limit=3 clean_requirements_on_remove=True best=False skip_if_unavailable=True max_parallel_downloads=5 fastestmirror=True deltarpm=True `

#### Configuration Options

| Option | Description | Default | Recommended | |--------|-------------|---------|-------------| | gpgcheck | Verify package signatures | 1 | 1 | | installonly_limit | Keep N versions of kernel | 3 | 3 | | clean_requirements_on_remove | Remove unused dependencies | True | True | | best | Always try to install best candidate | False | True | | skip_if_unavailable | Skip unavailable repositories | True | True | | max_parallel_downloads | Concurrent downloads | 3 | 5-10 | | fastestmirror | Use fastest mirror | False | True | | deltarpm | Use delta RPMs for updates | True | True |

User Configuration

Users can create personal configuration at ~/.config/dnf/dnf.conf or use aliases:

`bash

Add to ~/.bashrc

alias dnfi='sudo dnf install' alias dnfr='sudo dnf remove' alias dnfu='sudo dnf update' alias dnfs='dnf search' `

Troubleshooting

Common Issues and Solutions

#### Dependency Problems `bash

Check for broken dependencies

dnf check

Fix broken dependencies

sudo dnf autoremove

Force reinstall problematic package

sudo dnf reinstall package-name

Skip broken packages

sudo dnf install --skip-broken package-name `

#### Repository Issues `bash

Refresh repository metadata

sudo dnf clean metadata && sudo dnf makecache

Check repository status

dnf repolist --all

Test repository connectivity

dnf repoquery --available --quiet | head -1 `

#### Lock File Issues `bash

Remove lock file (if DNF crashed)

sudo rm -f /var/lib/dnf/locks/*

Check for running DNF processes

ps aux | grep dnf

Kill stuck DNF processes

sudo pkill dnf `

Error Messages and Solutions

| Error | Cause | Solution | |-------|-------|----------| | "No package X available" | Package not in repositories | Check repository configuration | | "Nothing to do" | Package already installed/updated | Use dnf list to verify status | | "Insufficient space" | Not enough disk space | Clean cache or free disk space | | "GPG signature verification failed" | Invalid package signature | Check GPG keys or use --nogpgcheck | | "Cannot retrieve metalink" | Network/repository issue | Check internet connection and repository URLs |

Debugging Commands

`bash

Verbose output for debugging

sudo dnf -v install package-name

Show detailed transaction information

sudo dnf -v update --assumeno

Check system integrity

sudo dnf check --duplicates

Verify installed packages

sudo rpm -Va `

Best Practices

Security Best Practices

1. Always verify GPG signatures `bash # Ensure gpgcheck=1 in configuration grep gpgcheck /etc/dnf/dnf.conf `

2. Keep system updated regularly `bash # Set up automatic security updates sudo dnf install dnf-automatic sudo systemctl enable --now dnf-automatic-install.timer `

3. Use trusted repositories only `bash # Review enabled repositories dnf repolist `

Performance Best Practices

1. Enable parallel downloads `ini # In /etc/dnf/dnf.conf max_parallel_downloads=10 `

2. Use fastest mirror `ini # In /etc/dnf/dnf.conf fastestmirror=true `

3. Regular cache maintenance `bash # Weekly cache cleanup sudo dnf clean all && sudo dnf makecache `

System Maintenance

#### Regular Maintenance Tasks

| Task | Frequency | Command | |------|-----------|---------| | System updates | Weekly | sudo dnf update | | Cache cleanup | Weekly | sudo dnf clean all | | Remove orphaned packages | Monthly | sudo dnf autoremove | | Check for broken dependencies | Monthly | dnf check | | Review installed packages | Quarterly | dnf list installed |

#### Automation Scripts

Create maintenance script /usr/local/bin/dnf-maintenance.sh:

`bash #!/bin/bash

DNF Maintenance Script

echo "Starting DNF maintenance..."

Update system

sudo dnf -y update

Remove orphaned packages

sudo dnf -y autoremove

Clean cache

sudo dnf clean all

Check for issues

dnf check

echo "DNF maintenance completed." `

Monitoring and Logging

#### Log Files

| Log File | Purpose | |----------|---------| | /var/log/dnf.log | DNF operations log | | /var/log/dnf.rpm.log | RPM transaction log | | /var/log/dnf.librepo.log | Repository access log |

#### Monitoring Commands `bash

Monitor real-time DNF operations

sudo tail -f /var/log/dnf.log

Check recent package installations

sudo dnf history | head -10

Review system changes

sudo rpm -qa --last | head -20 `

This comprehensive guide covers all aspects of DNF package management, from basic operations to advanced features and troubleshooting. Regular practice with these commands and adherence to best practices will ensure efficient and secure package management on Fedora and RHEL 8+ systems.

Tags

  • DNF
  • Fedora
  • RHEL
  • linux administration
  • package-management

Related Articles

Popular Technical Articles & Tutorials

Explore our comprehensive collection of technical articles, programming tutorials, and IT guides written by industry experts:

Browse all 8+ technical articles | Read our IT blog

DNF Package Manager: Complete Guide for Fedora/RHEL 8+