Starting from RHEL8, DNF is the default package management utility. It uses the following command line syntax.
#dnf [options] [arguments]
The following table lists important options and their description.
The dnf command | Description |
#dnf | Display brief information about important options and switches |
#dnf list | Display all installed and available-to-install packages from all configured repositories |
#dnf list installed | Display only installed packages |
#dnf repoquery --repo LocalRepo_BaseOS | Display all packages available to install on the LocalRepo_BaseOS repository |
#dnf info perl | Display information about the package perl |
#dnf install perl | Install the package perl |
#dnf -y update | Update all installed packages to their latest version |
#dnf update perl | Update the package perl |
#dnf remove perl | Remove the package perl |
Let's understand the above options in detail.
Without any option, the dnf command displays a brief description of all available options.
#dnf
DNF downloads packages from the configured repositories. To view a list of all configured and available repositories, use the repolist option.
#dnf repolist
When you install RedHat Linux, the installation process automatically configures the system to use RedHat's default repositories. To use these repositories, you need to purchase an active RedHat subscription. If you have an active RedHat subscription, DNF will automatically download the latest and updated packages from default repositories. If you don't have an active RedHat subscription, you can't use RedHat's default repositories. In that case, you have to configure at least one external or local repository from where DNF can download packages.
To learn how to configure a local repository from the RHEL installation disk, you can check the following tutorial.
To view all available packages for installation in all configured repositories, use the repoquery option.
#dnf repoquery
If you want to view all available packages for installation only from a specific repository, you need to specify its name as an argument with the --repo option. The following command lists all packages from the "LocalRepo_BaseOS" repository.
#dnf repoquery --repo LocalRepo_BaseOS
To list all installed packages and all packages available for installation from all enabled repositories, use the 'list' option.
#dnf list
This command shows output in three columns: package name, package version, and the name of the repository it was installed from. If the package was installed at the time of RHEL installation, it will display @anaconda in the third column.
To view a list of only installed packages, use the installed option with the list option.
#dnf list installed
You can filter the output of the above command with the grep command. For example, to view a list of all installed packages having the keyword zip in their name, use the following command.
#dnf list installed | grep zip
To know whether a specific package is installed or if not installed, whether it is available in any configured repository for installation, specify its name with the list option.
To install a package, specify its name as an argument with the install option. It not only installs the package you want it to install but also automatically installs all packages that are prerequisites to the package you want to install. For example, the following command installs the package perl and all of its dependent packages.
#dnf install perl
The above command resolves dependencies and shows a list of the packages it would install. It calculates the size of the packages and the amount of disk space the installation will consume.
By default, this command takes permission from the user before downloading and installing the package and its dependencies. After confirmation, it downloads and installs the packages. It also displays a list of installed packages at bottom of the output.
To perform an unattended installation, use the -y switch with the install option.
#dnf -y install perl
To update all installed packages to their latest available versions, use the update option.
#dnf -y update
This command will check for updates for all installed packages. If it finds an update for a package, it will update that package to the latest version.
If you want to update only a single package, you need to specify its name after the update option. For example, to update only the perl package, use the following command.
#dnf -y update perl
To remove a package, specify the package name after the remove option. The following command removes the package perl.
#dnf remove perl
To view information about a specific package, you can use the info option.
That's all for this tutorial. In this tutorial, we learned how to use the dnf command on Linux.