Use DNF on Oracle Linux

5
1
Send lab feedback

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).

  1. Run the dnf command without any options or arguments to view the usage. Pipe the output to less 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.

  2. Run the dnf repolist command to list the configured software repositories. This command lists only the enabled repositories by default.

    dnf repolist
  3. Run the dnf repoinfo command to list more detailed information. This command produces similar output as the dnf repolist -v command.

    dnf repoinfo

    The DNF repository metadata might go through a build process when you run this command.

  4. The dnf repolist list enabled repositories. Run the dnf repolist all to include any disabled repositories.

    dnf repolist all
  5. 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
  6. 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) 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.

  7. You can also use the dnf config-manager command to enable or disable repositories. Run the following command to disable the ol8_ksplice repository.

    dnf config-manager --disable ol8_ksplice
  8. Use the dnf config-manager command to enable the ol8_ksplice repository.

    dnf config-manager --enable ol8_ksplice

    Ensure that the ol8_ksplice repository is always enabled in production environments.

  9. To aid with performance, DNF caches data in /var/cache/dnf. There are times that this cached data may become stale and cause dnf commands to fail. To fix this problem, you can remove all the cached items by typing dnf 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 the dnf clean all command and retry the failed command.

Note: For information purposes only, there are various ways to add additional repositories. For example:

  1. Create a new .repo file in /etc/yum.repos.d
  2. 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>.
  3. 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

  1. 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
  2. Run the dnf list installed command to list all of the packages that are installed on your system.

    dnf list installed
  3. 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
  4. 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 the zsh package.

    dnf info zsh
  5. Run the dnf updateinfo list command to list all available errata (security, bug fixes, and enhancements).

    dnf updateinfo list
  6. Run the dnf updateinfo summary command to list a summary of available errata.

    dnf updateinfo summary
  7. Run the dnf updateinfo list bugfix command to list available bug fixes.

    dnf updateinfo list bugfix
  8. Run the dnf updateinfo list sec command to list available security upgrades.

    dnf updateinfo list sec
  9. 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
  10. You can list detailed information on available errata using the dnf updateinfo info command.

    dnf updateinfo info
  11. To list detailed information for a particular erratum, for example ELBA-2021-1603, run the dnf updateinfo info --advisory ELBA-2021-1603 command.

    dnf updateinfo info --advisory ELBA-2021-1603
  12. To list information for a particular Common Vulnerabilities and Exposures (CVE), for example, CVE-2021-0342, run the dnf updateinfo info --cve CVE-2021-0342 command.

    dnf updateinfo info --cve CVE-2021-0342
  13. 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 keyword php in the package name.

    dnf search php
  14. To determine which package provides a specific Linux command, use the dnf provides command. Run the following command to show the packages that provides the sudo command.

    dnf provides */sudo
  15. 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

  1. 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 the tmux package.

    dnf install tmux

    Answer y to confirm the package install.

  2. To avoid having to reply to the prompt, specify the -y option as in dnf install zsh -y to install the zsh 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.

  3. 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 the nginx 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 using dnf install dnf-plugins-core and try the download option again.

  4. 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.

  5. You can install RPM files using the rpm command, but it is recommended to always use dnf which will automatically detect and install any additional package dependencies that may be required. Type dnf install and the name of the nginx RPM file. The following is an example only. Provide the RPM file name obtained from output of the previous ls command.

    dnf install nginx-1.14.1-9.0.1.module+el8.0.0+5347+9282027e.x86_64.rpm
  6. 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 the nginx package.

    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 reinstall is that the reinstall will keep any custom configuration of files associated with the package.

Upgrade and Remove Packages

  1. Type dnf check-update to display the upgrades available for your installed packages.

    dnf check-update
  2. 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 the binutils 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.

  3. You can optionally exclude a specific package from the upgrade with the -x option. For example, use dnf upgrade -x kernel to exclude the kernel package while updating the remaining packages. To avoid waiting for the upgrade to complete, answer N when prompted for this lab.

    dnf upgrade -x kernel
  4. 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
  5. 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 using systemd timers. Run the following commands to install the package and enable the timer.

    dnf install dnf-automatic -y
    systemctl enable --now dnf-automatic.timer
  6. 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 upgrade_type parameter to security to only apply the security upgrades. Type the following command to view this parameter.

    grep upgrade_type /etc/dnf/automatic.conf
  7. 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 the nginx package.

    dnf remove nginx

Use the DNF History Feature

  1. 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, type dnf history.

    dnf history

    To get information related to one of the transactions, type dnf history info <transaction id>.

  2. Using the dnf remove nginx transaction as an example, you can undo the remove by typing dnf history undo <transaction id> -y. The following command assumes that the dnf remove nginx was transaction id 34.

    dnf history undo 34 -y
  3. You can redo the remove by typing dnf history redo <transaction id> -y. The following command assumes that the dnf remove nginx was transaction id 34.

    dnf history redo 34 -y
  4. 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

  1. 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
  2. The Server with GUI group 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"
  3. Run dnf group info on one of those smaller groups, for example Core, to show the individual packages.

    dnf group info core
  4. Type dnf group install "Server with GUI" to install the group. To avoid waiting for the install to complete, answer N 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 the dnf group remove <group name> command to remove a group.

For More Information

See other related resources:

SSR