Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux dnf command

Linux dnf command

Linux Command Reference Linux Command Reference


dnf (Dandified YUM) is a new generation of RPM package managers for RPM-based Linux distributions (such as Fedora, RHEL 8+, CentOS 8+, etc.). It is a replacement for yum, offering faster dependency resolution, a more modern codebase, and better performance.

The main features of dnf include:


dnf Basic Syntax

The basic syntax of the dnf command is:

dnf [选项] <命令> [参数]

Where:


Common dnf Commands

Package Management

Example

Install packages

dnf

install

Reinstall a package

dnf reinstall

Update a package

dnf update

Update all updatable packages

dnf update

Remove a package

dnf remove

Remove unneeded dependencies

dnf autoremove

Query Operations

Example

Search for packages

dnf search

List installed packages

dnf list installed

List all available packages

dnf list available

Display package information

dnf info

View the files provided by a package

dnf provides

Repository Management

Example

List all enabled repositories

dnf repolist

List all repositories (including disabled ones)

dnf repolist all

Enable a repository

dnf config-manager

--enable

Disable a repository

dnf config-manager

--disable

Add a new repository

dnf config-manager

--add-repo

System Upgrade

Example

Check for system upgrades

dnf check-update

Perform a system upgrade

dnf upgrade

Upgrade to a 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 the 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 a Development Tool Group

Example

Install the development tools group (including gcc, make, etc.)

sudo

dnf groupinstall

"Development Tools"

-y

Example 2: Find and Install Specific Software

Example

Search for packages containing nginx

dnf search nginx

Install nginx

sudo

dnf

install

nginx

-y

Start the nginx service

sudo

systemctl start nginx

Example 3: Clean the Cache

Example

Clean the downloaded package cache

sudo

dnf clean packages

Clean all caches (metadata and packages)

sudo

dnf clean all

Example 4: View History

Example

List dnf operation history

dnf

history

View detailed information about a specific transaction

dnf

history

info

Undo a specific transaction

dnf

history

undo


dnf Configuration Files

The main configuration file of dnf is located at /etc/dnf/dnf.conf, common configuration items include:

Example

[main]

gpgcheck

=

1 # Whether to check GPG signatures

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 is usually faster than Slower
Plugin system Compatible with yum plugins Native plugins
History records More detailed Basic records

Common Problem Solutions

1. Dependency Conflicts

Example

Try to resolve dependency issues automatically

sudo

dnf

--skip-broken

install

Or try to exclude specific packages

sudo

dnf

install

 

--exclude

=

2. Corrupted Repository Metadata

Example

Clean and rebuild the repository cache

sudo

dnf clean all

sudo

dnf makecache

3. Package Version Locking

Example

Lock packages to prevent updates

sudo

dnf versionlock add

List locked packages

sudo

dnf versionlock list

Remove a lock

sudo

dnf versionlock delete


Best Practices

  1. Update the system regularly:

    sudo dnf update -y
  2. Search before installing:

    dnf search 
  3. Review the impact of changes:

    sudo dnf update --assumeno
  4. Use group commands to manage related software:

    # 列出可用组
    
    

dnf group list

Install a group

sudo dnf groupinstall "group name" 5.

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 and gradually become familiar with their various features.


Linux Command Reference Linux Command Reference