Note:
- This tutorial is available in an Oracle-provided free lab environment.
- It uses example values for Oracle Cloud Infrastructure credentials, tenancy, and compartments. When completing your lab, substitute these values with ones specific to your cloud environment.
Use DNF on Oracle Linux
Introduction
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.
Objectives
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).
-
Run the
dnf
command without any options or arguments to view the usage. Pipe the output toless
to 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.
-
Run the
dnf repolist
command to list the configured software repositories. This command lists only the enabled repositories by default.dnf repolist
-
Run the
dnf repoinfo
command to list more detailed information. This command produces similar output as thednf repolist -v
command.dnf repoinfo
The DNF repository metadata might go through a build process when you run this command.
-
The
dnf repolist
list enabled repositories. Run thednf repolist all
to include any disabled repositories.dnf repolist all
-
The
dnf
command automatically searches the/etc/yum.repos.d
directory for files with the suffix.repo
and 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/etc/yum.repos.d
directory.cd /etc/yum.repos.d ls -l
-
View the contents of the
ksplice-ol8.repo
file in the/etc/yum.repos.d
directory.cat ksplice-ol8.repo
Notice that this file defines two repositories,
ol8_ksplice
, which is enabled (enabled=1) andol8_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-manager
command to enable or disable repositories. Run the following command to disable theol8_ksplice
repository.dnf config-manager --disable ol8_ksplice
-
Use the
dnf config-manager
command to enable theol8_ksplice
repository.dnf config-manager --enable ol8_ksplice
Ensure that the
ol8_ksplice
repository 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 causednf
commands to fail. To fix this problem, you can remove all the cached items by typingdnf clean all
.dnf clean all
The
dnf
command automatically rebuilds this cache over time as you run various commands. If any problems occur in this lab, run thednf clean all
command and retry the failed command.
Note: For information purposes only, there are various ways to add additional repositories. For example:
- Create a new
.repo
file in/etc/yum.repos.d
- Use the
dnf config-manager
command 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
-
Run the
dnf list
command to list all of the packages that are available in all enabled repositories and all packages that are installed on your system.dnf list
-
Run the
dnf list installed
command to list all of the packages that are installed on your system.dnf list installed
-
Run the
dnf list available
command to list all of the packages that are available to be installed in all enabled repositories.dnf list available
-
Run the
dnf info
command 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 thezsh
package.dnf info zsh
-
Run the
dnf updateinfo list
command to list all available errata (security, bug fixes, and enhancements).dnf updateinfo list
-
Run the
dnf updateinfo summary
command to list a summary of available errata.dnf updateinfo summary
-
Run the
dnf updateinfo list bugfix
command to list available bug fixes.dnf updateinfo list bugfix
-
Run the
dnf updateinfo list sec
command 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=Important
command to list Important security upgrades.dnf updateinfo list --sec-severity=Important
-
You can list detailed information on available errata using the
dnf updateinfo info
command.dnf updateinfo info
-
To list detailed information for a particular erratum, for example
ELBA-2021-1603
, run thednf updateinfo info --advisory ELBA-2021-1603
command.dnf updateinfo info --advisory ELBA-2021-1603
-
To list information for a particular Common Vulnerabilities and Exposures (CVE), for example,
CVE-2021-0342
, run thednf updateinfo info --cve CVE-2021-0342
command.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 php
list packages that have the keywordphp
in the package name.dnf search php
-
To determine which package provides a specific Linux command, use the
dnf provides
command. Run the following command to show the packages that provides thesudo
command.dnf provides */sudo
-
Use the
dnf provides
command to determine which package provides a specific file. Provide the fully qualified file path, for example/etc/sudo.conf
.dnf provides /etc/sudo.conf
Install, Download, and Reinstall Packages
-
To install a software package, run the
dnf install
command followed by the name of the software package to install. Run the following command to install thetmux
package.dnf install tmux
Answer
y
to confirm the package install. -
To avoid having to reply to the prompt, specify the
-y
option as indnf install zsh -y
to install thezsh
package.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 download
command followed by the name of the software package to download. Run the following command to download thenginx
package.dnf download nginx
When using the download option, DNF requires the
dnf-plugins-core
package, which gets installed on Oracle Linux 8 as part of a Minimal Install. If it was missing, you could install the plugin usingdnf install dnf-plugins-core
and try the download option again. -
The download option provides an RPM file. Use the
ls
command to view the RPM file in the current directory.ls
If the RPM file does not exist, use
sudo
and run the previous download command again,sudo dnf download nginx
. -
You can install RPM files using the
rpm
command, but it is recommended to always usednf
which will automatically detect and install any additional package dependencies that may be required. Typednf install
and the name of thenginx
RPM file. The following is an example only. Provide the RPM file name obtained from output of the previousls
command.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 reinstall
command followed by the name of the software package to reinstall. Run the following command to reinstall thenginx
package.dnf reinstall nginx
This option would be the same as performing a
dnf remove
, followed by adnf install
. The critical difference with usingdnf reinstall
is that the reinstall will keep any custom configuration of files associated with the package.
Upgrade and Remove Packages
-
Type
dnf check-update
to display the upgrades available for your installed packages.dnf check-update
-
To upgrade a single package, type
dnf upgrade
followed by the package name. Include the-y
option to avoid having to reply to the confirmation prompt. Run the following command to upgrade thebinutils
package.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
-x
option. For example, usednf upgrade -x kernel
to exclude the kernel package while updating the remaining packages. To avoid waiting for the upgrade to complete, answerN
when 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
N
when prompted for this tutorial.dnf upgrade --advisory ELBA-2021-1603 dnf upgrade --cve CVE-2021-0342
-
An alternative to manually running
dnf upgrade
is to use the DNF Automatic Tool. This tool provides automatic notifications of upgrades, download upgrades, and the installs them automatically by usingsystemd
timers. 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 theupgrade_type
parameter tosecurity
to 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 remove
command followed by the name of the software package to remove. Run the following command to remove thenginx
package.dnf remove nginx
Use the DNF History Feature
-
The DNF history feature shows all the actions performed by the
dnf
command. The history feature allows for undo, redo, and rollback of a specific DNF transaction. To see all transactions, typednf history
.dnf history
To get information related to one of the transactions, type
dnf history info <transaction id>
. -
Using the
dnf remove nginx
transaction as an example, you canundo
the remove by typingdnf history undo <transaction id> -y
. The following command assumes that thednf remove nginx
was transaction id 34.dnf history undo 34 -y
-
You can
redo
the remove by typingdnf history redo <transaction id> -y
. The following command assumes that thednf remove nginx
was 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.
cat /var/log/dnf.log
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 list
to get the group names.dnf group list
-
The
Server with GUI
group will install a graphical desktop on a minimal console only install. Typednf group info "Server with GUI"
to show the group consists of other groups.dnf group info "Server with GUI"
-
Run
dnf group info
on one of those smaller groups, for exampleCore
, to show the individual packages.dnf group info core
-
Type
dnf group install "Server with GUI"
to install the group. To avoid waiting for the install to complete, answerN
when 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 thednf group remove <group name>
command to remove a group.
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.