Linux Comm Dnf
[ Linux Command Manual](#)
* * *
dnf (Dandified YUM) is the next-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:
* Installing, updating, and removing packages from software repositories
* Automatically resolving package dependencies
* Querying package information
* Managing software repositories
* * *
## dnf Basic Syntax
The basic syntax format of the dnf command is:
dnf
Where:
* ``: Optional parameters used to modify dnf behavior
* ``: The main operation to be performed (such as install, remove, etc.)
* ``: Additional information required by the command (usually package names)
* * *
## Common dnf Commands
### Package Management
## Examples
# Install package
dnf install
# Reinstall package
dnf reinstall
# Update package
dnf update
# Update all updatable packages
dnf update
# Remove package
dnf remove
# Remove unnecessary dependencies
dnf autoremove
### Query Operations
## Examples
# Search for packages
dnf search
# List installed packages
dnf list installed
# List all available packages
dnf list available
# Display package information
dnf info
# View files provided by package
dnf provides
### Repository Management
## Examples
# List all enabled repositories
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
# Check for system updates
dnf check-update
# Perform system upgrade
dnf upgrade
# Upgrade to new release
dnf system-upgrade
* * *
## Common dnf 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
# Install development tools group (includes gcc, make, etc.)
sudo dnf groupinstall "Development Tools"-y
### Example 2: Find and Install Specific Software
## Examples
# Search for packages containing nginx
dnf search nginx
# Install nginx
sudo dnf install nginx -y
# Start nginx service
sudo systemctl start nginx
### Example 3: Clean Cache
## Examples
# Clean downloaded package cache
sudo dnf clean packages
# Clean all cache (metadata and packages)
sudo dnf clean all
### Example 4: View History
## Examples
# List dnf operation history
dnf history
# View detailed information of specific transaction
dnf history info
# Undo specific transaction
dnf history undo
* * *
## dnf Configuration File
The main configuration file for dnf is located at `/etc/dnf/dnf.conf`. Common configuration items include:
## Examples
gpgcheck=1 # Whether to check GPG signatures
installonly_limit=3 # Number of kernel versions to keep
clean_requirements_on_remove=True # Clean 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
* * *
## dnf vs yum Comparison
| 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
# Try to automatically resolve dependency issues
sudo dnf --skip-broken install
# Or try to exclude specific packages
sudo dnf install--exclude=
### 2. Corrupted Repository Metadata
## Examples
# Clean and rebuild repository cache
sudo dnf clean all
sudo dnf makecache
### 3. Package Version Locking
## Examples
# Lock package to prevent updates
sudo dnf versionlock add
# List locked packages
sudo dnf versionlock list
# Remove lock
sudo dnf versionlock delete
* * *
## Best Practices
1. **Regularly update the system**:
sudo dnf update -y
2. **Search before installing**:
dnf search <keyword>
3. **View impact of changes**:
sudo dnf update --assumeno
4. **Use group commands to manage related software**:
# List available groups dnf group list # Install group sudo dnf groupinstall "group name"
5. **Keep repositories clean**:
# Regularly clean unnecessary packages 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, and gradually become familiar with its various functions.
* * Linux Command Manual](#)
YouTip