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 dnfOn 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] `
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 vimInstall with automatic confirmation
sudo dnf -y install gitInstall specific version
sudo dnf install vim-8.2.1234`#### Multiple Package Installation
`bash
Install multiple packages
sudo dnf install vim git curl wgetInstall from local RPM file
sudo dnf install /path/to/package.rpmInstall 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-nameInstall with best candidate selection
sudo dnf install --best package-name`Removing Packages
#### Basic Removal
`bash
Remove single package
sudo dnf remove firefoxRemove multiple packages
sudo dnf remove firefox thunderbirdRemove with dependencies (autoremove)
sudo dnf autoremove firefox`#### Advanced Removal Options
`bash
Remove packages and unused dependencies
sudo dnf remove firefox && sudo dnf autoremoveRemove 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 updateUpdate with automatic confirmation
sudo dnf -y updateCheck for available updates
sudo dnf check-update`#### Selective Updates
`bash
Update specific package
sudo dnf update firefoxUpdate packages from specific repository
sudo dnf --enablerepo=updates updateUpdate 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 firefoxSearch 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 firefoxShow package dependencies
dnf repoquery --requires firefoxShow what packages depend on this package
dnf repoquery --whatrequires firefoxList files in package
dnf repoquery --list firefox`#### Listing Packages
`bash
List all installed packages
dnf list installedList available packages
dnf list availableList upgradeable packages
dnf list upgradesList packages by pattern
dnf list "firefox"`Package Groups
#### Group Operations
`bash
List available groups
dnf group listInstall 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 repolistList all repositories (enabled and disabled)
dnf repolist --allShow repository information
dnf repoinfo fedora`#### Repository Operations
`bash
Enable repository temporarily
sudo dnf --enablerepo=updates-testing install packageDisable repository temporarily
sudo dnf --disablerepo=updates install packageEnable repository permanently
sudo dnf config-manager --set-enabled repository-nameDisable 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.repoAdd RPM Fusion repositories (Fedora)
sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpmAdd 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 listShow module information
dnf module info nodejsInstall module stream
sudo dnf module install nodejs:14Enable module stream
sudo dnf module enable nodejs:14Disable module
sudo dnf module disable nodejsReset 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 historyShow detailed transaction information
dnf history info 5Undo transaction
sudo dnf history undo 5Redo transaction
sudo dnf history redo 5Rollback 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 -sDownload packages to specific directory
sudo dnf download --destdir=/tmp firefoxShow package changelog
dnf changelog firefoxFind which package owns a file
dnf provides /usr/bin/git`Performance Optimization
#### Cache Management
`bash
Clean all cache
sudo dnf clean allClean only metadata
sudo dnf clean metadataClean packages cache
sudo dnf clean packagesMake 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 checkFix broken dependencies
sudo dnf autoremoveForce reinstall problematic package
sudo dnf reinstall package-nameSkip broken packages
sudo dnf install --skip-broken package-name`#### Repository Issues
`bash
Refresh repository metadata
sudo dnf clean metadata && sudo dnf makecacheCheck repository status
dnf repolist --allTest 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 dnfKill 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-nameShow detailed transaction information
sudo dnf -v update --assumenoCheck system integrity
sudo dnf check --duplicatesVerify 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 updateRemove orphaned packages
sudo dnf -y autoremoveClean cache
sudo dnf clean allCheck for issues
dnf checkecho "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.logCheck recent package installations
sudo dnf history | head -10Review 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.