DNF Command Examples

DNF (or Dandified YUM) is the next generation version of the YUM (Yellowdog Updater, Modified). On some newer RPM-based Linux distributions (e.g. Fedora 22, CentOS 8 and RHEL 8) yum command is a symbolic link to the dnf binary.

Here use git as an example to demonstrate how to use dnf command, you can replace git with any package name you want.

If you are not the root user, please make sure to add sudo before dnf.

Basic usage

To search the exact name of a package by any characters:

dnf search git

To check information of a package:

dnf info git

To install a package of latest version:

dnf install git

To install multiple packages:

dnf install git python39 mysql

To install packages without any prompt:

dnf install git -y

To list all installed packages:

dnf list --installed

To check whether a package has been installed:

dnf list git --installed

To show all versions of a package in repositories:

dnf list git --showduplicates

To install a package of a specific version get from above:

dnf install git-2.27.0-1.el8

To reinstall an installed package:

dnf reinstall git

To upgrade an installed package:

dnf upgrade git

To downgrade an installed package:

dnf downgrade git

To remove (uninstall) a package:

dnf remove git

To remove a package and unneeded dependencies:

dnf autoremove git

To list all history commands of complete transaction:

dnf history

Advanced usage

To show enabled repositories only:

dnf repolist

To show all repositories including the disabled:

dnf repolist all

To show information of a specific repository:

dnf repoinfo powertools

To show information of all repositories:

dnf repoinfo

To enable repositories permanently:

dnf config-manager --enable epel,powertools

To disable repositories permanently:

dnf config-manager --disable epel,powertools

To enable repositories temporarily while installing package:

dnf install git --enablerepo=epel,powertools

To disable repositories temporarily while installing package:

dnf install git --disablerepo=epel,powertools

To show details of an installed package:

dnf repoquery -i git --installed

To list all files of an installed package:

dnf repoquery -l git --installed

To upgrade all packages to latest version:

dnf upgrade

To upgrade all packages excluding the specific packages:

dnf upgrade --exclude=git,gcc

To remove all temporary files kept for repositories:

dnf clean all

Learn more

To show help of all available commands and options:

dnf -h

To show help of a specific command:

dnf repoquery -h

To learn more from manual:

man dnf

Useful resources:

Leave a comment

Your email address will not be published. Required fields are marked *