Use DNF on Oracle Linux
The following tutorial provides practical examples of using the Dandified YUM (DNF) package manager on Oracle Linux. This tutorial is targeted at users of Oracle Linux 8 or later.
In this lab, you'll learn how to:
- Work with DNF repositories
- List package information
- Install, download, and reinstall packages
- Upgrade and remove packages
- Use the DNF history feature
- Manage package groups
What Do You Need?
- A system with Oracle Linux 8 installed.
Work with DNF Repositories
Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.
Some of the
dnf commands in this lab need to be proceeded by
sudo. Otherwise you will get the following message:
Error: This command has to be run with superuser privileges (under the root user on most systems).
dnfcommand without any options or arguments to view the usage. Pipe the output to
lessto view one page at a time.
dnf | less
This displays a list of main commands, a list of plugin commands, and general DNF options. Press the Enter key to view the next line or press the Spacebar to view the next page. Press the q key to return to the shell prompt.
dnf repolistcommand to list the configured software repositories. This command lists only the enabled repositories by default.
dnf repoinfocommand to list more detailed information. This command produces similar output as the
dnf repolist -vcommand.
The DNF repository metadata might go through a build process when you run this command.
dnf repolistlist enabled repositories. Run the
dnf repolist allto include any disabled repositories.
dnf repolist all
dnfcommand automatically searches the
/etc/yum.repos.ddirectory for files with the suffix
.repoand appends these to the configuration when it is processing. Use this directory to define repository files for repositories that you want to make available. View the contents of the
cd /etc/yum.repos.d ls -l
View the contents of the
ksplice-ol8.repofile in the
Notice that this file defines two repositories,
ol8_ksplice, which is enabled (enabled=1) and
ol8_x86_64_userspace_ksplice, which is disabled (enabled=0). To enable a repository, edit the file and change enabled=0 to enabled=1.
You can also use the
dnf config-managercommand to enable or disable repositories. Run the following command to disable the
dnf config-manager --disable ol8_ksplice
dnf config-managercommand to enable the
dnf config-manager --enable ol8_ksplice
Ensure that the
ol8_ksplicerepository is always enabled in production environments.
To aid with performance, DNF caches data in
/var/cache/dnf. There are times that this cached data may become stale and cause
dnfcommands to fail. To fix this problem, you can remove all the cached items by typing
dnf clean all.
dnf clean all
dnfcommand automatically rebuilds this cache over time as you run various commands. If any problems occur in this lab, run the
dnf clean allcommand and retry the failed command.
Note: For information purposes only, there are various ways to add additional repositories. For example:
- Create a new
- Use the
dnf config-managercommand to add a repository at a specified URL, for example,
dnf config-manager --add-repo <https://example.com/my_repository.repo>.
- If the repository has a Red Hat Package Manager (RPM) install file, the repository can be added using
dnf install <url_of_repo_rpm_file>.
List Package Information
dnf listcommand to list all of the packages that are available in all enabled repositories and all packages that are installed on your system.
dnf list installedcommand to list all of the packages that are installed on your system.
dnf list installed
dnf list availablecommand to list all of the packages that are available to be installed in all enabled repositories.
dnf list available
dnf infocommand followed by the name of the software package to view detailed information about the package. For example, run the following command to view information about the
dnf info zsh
dnf updateinfo listcommand to list all available errata (security, bug fixes, and enhancements).
dnf updateinfo list
dnf updateinfo summarycommand to list a summary of available errata.
dnf updateinfo summary
dnf updateinfo list bugfixcommand to list available bug fixes.
dnf updateinfo list bugfix
dnf updateinfo list seccommand to list available security upgrades.
dnf updateinfo list sec
You can list security upgrades based on severity (Critical, Important, Moderate, Low). For example, run the
dnf updateinfo list --sec-severity=Importantcommand to list Important security upgrades.
dnf updateinfo list --sec-severity=Important
You can list detailed information on available errata using the
dnf updateinfo infocommand.
dnf updateinfo info
To list detailed information for a particular erratum, for example
ELBA-2021-1603, run the
dnf updateinfo info --advisory ELBA-2021-1603command.
dnf updateinfo info --advisory ELBA-2021-1603
To list information for a particular Common Vulnerabilities and Exposures (CVE), for example,
CVE-2021-0342, run the
dnf updateinfo info --cve CVE-2021-0342command.
dnf updateinfo info --cve CVE-2021-0342
DNF provides a search option if you don't know the exact name of a package. For example,
dnf search phplist packages that have the keyword
phpin the package name.
dnf search php
To determine which package provides a specific Linux command, use the
dnf providescommand. Run the following command to show the packages that provides the
dnf provides */sudo
dnf providescommand to determine which package provides a specific file. Provide the fully qualified file path, for example
dnf provides /etc/sudo.conf
Install, Download, and Reinstall Packages
To install a software package, run the
dnf installcommand followed by the name of the software package to install. Run the following command to install the
dnf install tmux
yto confirm the package install.
To avoid having to reply to the prompt, specify the
-yoption as in
dnf install zsh -yto install the
dnf install zsh -y
For information purposes, to install a package from a disabled repository, use the
dnf --enablerepo=<repo name> install <package name>command.
To download a software package rather than installing it, run the
dnf downloadcommand followed by the name of the software package to download. Run the following command to download the
dnf download nginx
When using the download option, DNF requires the
dnf-plugins-corepackage, which gets installed on Oracle Linux 8 as part of a Minimal Install. If it was missing, you could install the plugin using
dnf install dnf-plugins-coreand try the download option again.
The download option provides an RPM file. Use the
lscommand to view the RPM file in the current directory.
If the RPM file does not exist, use
sudoand run the previous download command again,
sudo dnf download nginx.
You can install RPM files using the
rpmcommand, but it is recommended to always use
dnfwhich will automatically detect and install any additional package dependencies that may be required. Type
dnf installand the name of the
nginxRPM file. The following is an example only. Provide the RPM file name obtained from output of the previous
dnf install nginx-1.14.1-9.0.1.module+el8.0.0+5347+9282027e.x86_64.rpm
If a package is having issues, use
dnf reinstallcommand followed by the name of the software package to reinstall. Run the following command to reinstall the
dnf reinstall nginx
This option would be the same as performing a
dnf remove, followed by a
dnf install. The critical difference with using
dnf reinstallis that the reinstall will keep any custom configuration of files associated with the package.
Upgrade and Remove Packages
dnf check-updateto display the upgrades available for your installed packages.
To upgrade a single package, type
dnf upgradefollowed by the package name. Include the
-yoption to avoid having to reply to the confirmation prompt. Run the following command to upgrade the
dnf upgrade binutils -y
To upgrade all packages, use
dnf upgrade. Do not run this command in this tutorial because it takes several minutes to apply all available upgrades.
You can optionally exclude a specific package from the upgrade with the
-xoption. For example, use
dnf upgrade -x kernelto exclude the kernel package while updating the remaining packages. To avoid waiting for the upgrade to complete, answer
Nwhen prompted for this lab.
dnf upgrade -x kernel
To upgrade only packages that correspond to a specific erratum or CVE, run the following commands. To avoid waiting for the upgrade to complete, answer
Nwhen prompted for this tutorial.
dnf upgrade --advisory ELBA-2021-1603 dnf upgrade --cve CVE-2021-0342
An alternative to manually running
dnf upgradeis to use the DNF Automatic Tool. This tool provides automatic notifications of upgrades, download upgrades, and the installs them automatically by using
systemdtimers. Run the following commands to install the package and enable the timer.
dnf install dnf-automatic -y systemctl enable --now dnf-automatic.timer
The configuration file for the DNF Automatic Tool is
/etc/dnf/automatic.conf. By default, the automatic upgrade applies all available upgrades. You can change the
securityto only apply the security upgrades. Type the following command to view this parameter.
grep upgrade_type /etc/dnf/automatic.conf
To remove a software package, run the
dnf removecommand followed by the name of the software package to remove. Run the following command to remove the
dnf remove nginx
Use the DNF History Feature
The DNF history feature shows all the actions performed by the
dnfcommand. The history feature allows for undo, redo, and rollback of a specific DNF transaction. To see all transactions, type
To get information related to one of the transactions, type
dnf history info <transaction id>.
dnf remove nginxtransaction as an example, you can
undothe remove by typing
dnf history undo <transaction id> -y. The following command assumes that the
dnf remove nginxwas transaction id 34.
dnf history undo 34 -y
redothe remove by typing
dnf history redo <transaction id> -y. The following command assumes that the
dnf remove nginxwas transaction id 34.
dnf history redo 34 -y
In addition to DNF history, package installations, updates, and removals are logged in the /var/log/dnf.log file.
Manage Package Groups
DNF further allows for the install, update, or removal of package groups. These groups are a group of dependent packages that serve a common purpose. Use
dnf group listto get the group names.
dnf group list
Server with GUIgroup will install a graphical desktop on a minimal console only install. Type
dnf group info "Server with GUI"to show the group consists of other groups.
dnf group info "Server with GUI"
dnf group infoon one of those smaller groups, for example
Core, to show the individual packages.
dnf group info core
dnf group install "Server with GUI"to install the group. To avoid waiting for the install to complete, answer
Nwhen prompted for this lab.
dnf group install "Server with GUI"
Note: For informational purposes only, use the
dnf group update <group name>command to update a group. Use the
dnf group remove <group name>command to remove a group.
For More Information
See other related resources: