Linux dnf Command
dnf (Dandified YUM) is a new-generation RPM package manager for RPM-based Linux distributions (such as Fedora, RHEL 8+, CentOS 8+, etc.). It is a replacement for yum, providing faster dependency resolution, a more modern codebase, and better performance.
The main functions of dnf include:
- Install, update, and delete packages from software repositories
- Automatically resolve package dependencies
- Query package information
- Manage software repositories
dnf Basic Syntax
The basic syntax format of the dnf command is:
dnf [选项] <命令> [参数]
Where:
[Options]: optional arguments used to modify dnf behavior<Command>: the main operation to perform (such as install, remove, etc.)[Parameters]: additional information required by the command (usually the package name)
Common dnf Commands
Package Management
Examples
dnf install
# Reinstall package
dnf reinstall
# Update package
dnf update
# Update all updatable packages
dnf update
# Remove package
dnf remove
# Remove unneeded dependencies
dnf autoremove
Query Operations
Examples
dnf search
# List installed packages
dnf list installed
# List all available packages
dnf list available
# Show package information
dnf info
# View files provided by the package
dnf provides
Repository Management
Examples
dnf repolist
# List all repositories (including disabled)
dnf repolist all
# Enable repository
dnf config-manager --enable
# Disable repository
dnf config-manager --disable
# Add new repository
dnf config-manager --add-repo
System Upgrade
Examples
dnf check-update
# Perform system upgrade
dnf upgrade
# Upgrade to a new release
dnf system-upgrade
dnf Common Options
| Option | Description |
|---|---|
-y |
Automatically answer "yes" |
-q |
Quiet mode, reduce output |
-v |
Verbose output |
--refresh |
Refresh repository metadata before operation |
--nogpgcheck |
Disable GPG signature checking |
--skip-broken |
Skip problematic packages |
--best |
Try to install the best available version |
Practical Application Examples
Example 1: Install Development Tools Group
Examples
sudo dnf groupinstall "Development Tools" -y
Example 2: Find and Install Specific Software
Examples
dnf search nginx
# Install nginx
sudo dnf install nginx -y
# Start nginx service
sudo systemctl start nginx
Example 3: Clean Cache
Examples
sudo dnf clean packages
# Clean all caches (metadata and packages)
sudo dnf clean all
Example 4: View History
Examples
dnf history
# View detailed information of a specific transaction
dnf history info
# Undo a specific transaction
dnf history undo
dnf Configuration File
The main configuration file of dnf is located at/etc/dnf/dnf.conf, common configuration items include:
Examples
gpgcheck=1 # Whether to check GPG signature
installonly_limit=3 # Number of kernel versions to keep
clean_requirements_on_remove=True # Clean up dependencies when removing
best=True # Always try to install the best version
You can view the current configuration with the following command:
dnf config-manager --dump
Comparison of dnf and yum
| Feature | dnf | yum |
|---|---|---|
| Dependency resolution algorithm | libsolv (faster) | Custom (slower) |
| API | Stable | Unstable |
| Memory usage | Lower | Higher |
| Performance | Faster | Slower |
| Plugin system | Compatible with yum plugins | Native plugins |
| History | More detailed | Basic records |
Common Problem Solving
1. Dependency Conflicts
Examples
sudo dnf --skip-broken install
# Or try to exclude a specific package
sudo dnf install --exclude=
2. Repository Metadata Corruption
Examples
sudo dnf clean all
sudo dnf makecache
3. Package Version Locking
Examples
sudo dnf versionlock add
# List locked packages
sudo dnf versionlock list
# Remove lock
sudo dnf versionlock delete
Best Practices
-
Update the system regularly:
sudo dnf update -y
-
Search before installing:
dnf search <keyword>
-
Check the impact of changes:
sudo dnf update --assumeno
-
Use group commands to manage related software:
# 列出可用组 dnf group list # 安装组 sudo dnf groupinstall "组名"
-
Keep repositories clean:
# 定期清理不需要的包 sudo dnf autoremove
Through this article, you should have mastered the basic usage and advanced techniques of the dnf command. As a package management tool for modern RPM systems, dnf provides powerful and efficient software management capabilities. It is recommended to try different commands and options in actual use to gradually become familiar with its various functions.
Other Extensions