Using DNF to Manage Software Packages

DNF is a Linux software package management tool used to manage RPM software packages. The DNF can query software package information, obtain software packages from a specified software library, automatically process dependencies to install or uninstall software packages, and update the system to the latest available version.

NOTE:

  • DNF is fully compatible with YUM and provides YUM-compatible command lines and APIs for extensions and plug-ins.
  • You must have the administrator rights to use the DNF. All commands in this chapter must be executed by the administrator.

Configuring the DNF

The DNF Configuration File

The main configuration file of the DNF is /etc/dnf/dnf.conf which consists of two parts:

  • The main part in the file stores the global settings of the DNF.

  • The repository part in the file stores the settings of the software source. You can add one or more repository sections to the file.

In addition, the /etc/yum.repos.d directory stores one or more repo source files, which define different repositories.

You can configure a software source by either directly configuring the /etc/dnf/dnf.conf file or configuring the .repo file in the /etc/yum.repos.d directory.

Configuring the main Part

The /etc/dnf/dnf.conf file contains the main part. The following is an example of the configuration file:

[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False

Common options are as follows:

Table 1 main parameter description

Parameter

Description

cachedir

Cache directory for storing RPM packages and database files.

keepcache

The options are 1 and 0, indicating whether to cache the RPM packages and header files that have been successfully installed. The default value is 0, indicating that the RPM packages and header files are not cached.

debuglevel

Sets debugging information generated by the DNF. The value ranges from 0 to 10. A larger value indicates more detailed debugging information. The default value is 2. The value 0 indicates that the debug information is not displayed.

clean_requirements_on_remove

Deletes the dependency items that are no longer used during DNF removal. If the software package is installed through the DNF instead of the explicit user request, the software package can be deleted only through clean_requirements_on_remove, that is, the software package is introduced as a dependency item. The default value is True.

best

The system always attempts to install the latest version of the upgrade package. If the latest version cannot be installed, the system displays the cause and stops the installation. The default value is True.

obsoletes

The options are 1 and 0, indicating whether to allow the update of outdated RPM packages. The default value is 1, indicating that the update is allowed.

gpgcheck

The options are 1 and 0, indicating whether to perform GPG verification. The default value is 1, indicating that verification is required.

plugins

The options are 1 and 0, indicating that the DNF plug-in is enabled or disabled. The default value is 1, indicating that the DNF plug-in is enabled.

installonly_limit

Sets the number of packages that can be installed at the same time by running the installonlypkgs command. The default value is 3. You are advised not to decrease the value.

Configuring the repository Part

The repository part allows you to customize openEuler software source repositories. The name of each repository must be unique. Otherwise, conflicts may occur. You can configure a software source by either directly configuring the /etc/dnf/dnf.conf file or configuring the .repo file in the /etc/yum.repos.d directory.

  • Configuring the /etc/dnf/dnf.conf file

    The following is a minimum configuration example of the [repository] section:

    [repository]
    name=repository_name
    baseurl=repository_url
    

    NOTE:
    openEuler provides an online image source at https://repo.openeuler.org/. For example, if the openEuler 21.03 version is aarch64, the baseurl can be set to https://repo.openeuler.org/openEuler-21.03/OS/aarch64/.

    Common options are as follows:

    Table 2 repository parameter description

    Parameter

    Description

    name=repository_name

    Name string of a software repository.

    baseurl=repository_url

    Address of the software repository.

    • Network location using the HTTP protocol, for example, http://path/to/repo
    • Network location using the FTP protocol, for example, ftp://path/to/repo
    • Local path: for example, file:///path/to/local/repo
  • Configuring the .repo file in the /etc/yum.repos.d directory openEuler provides multiple repo sources for users online. For details about the repo sources, see System Installation.

    For example, run the following command as the root user to add the openeuler repo source to the openEuler.repo file.

    # vi /etc/yum.repos.d/openEuler.repo
    
    [OS]
    name=openEuler-$releasever - OS
    baseurl=https://repo.openeuler.org/openEuler-21.03/OS/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=https://repo.openeuler.org/openEuler-21.03/OS/$basearch/RPM-GPG-KEY-openEuler
    

    NOTE:

    • enabled indicates whether to enable the software source repository. The value can be 1 or 0. The default value is 1, indicating that the software source repository is enabled.
    • gpgkey is the public key used to verify the signature.

Displays the Current Configuration

  • To display the current configuration information, run the following command:

    dnf config-manager --dump
    
  • To display the configuration of a software source, query the repo id:

    dnf repolist
    

    Run the following command to display the software source configuration of the corresponding ID. In the command, repository indicates the repository ID.

    dnf config-manager --dump repository
    
  • You can also use a global regular expression to display all matching configurations.

    dnf config-manager --dump glob_expression
    

Creating a Local Software Repository

To create a local repository of software sources, perform the following steps.

  1. Install the createrepo software package. Run the following command as the root user:

    dnf install createrepo
    
  2. Copy the required software packages to a directory, for example, /mnt/local_repo/.

  3. Run the following command to create a software source:

    createrepo /mnt/local_repo
    

Adding, Enabling, and Disabling Software Sources

This section describes how to add, enable, and disable the software source repository by running the dnf config-manager command.

Adding Software Source

To define a new software repository, you can add the repository part to the /etc/dnf/dnf.conf file or add the .repo file to the /etc/yum.repos.d/ directory. You are advised to add the .repo file. Each software source has its own .repo file. The following describes how to add the .repo file.

To add such a source to your system, run the following command as the user root. After the command is executed, the corresponding .repo file is generated in the /etc/yum.repos.d/ directory. In the command, repository_url indicates the repo source address. For details, see Table 2.

dnf config-manager --add-repo repository_url

Enabling a Software Repository

To enable the software source, run the following command as the user root. In the command, repository indicates the repository ID in the new .repo file. You can run the dnf repolist command to query the repository ID.

dnf config-manager --set-enable repository

You can also use a global regular expression to enable all matching software sources. In the command, glob_expression indicates the regular expression used to match multiple repository IDs.

dnf config-manager --set-enable glob_expression

Disabling a Software Repository

To disable a software source, run the following command as the user root:

dnf config-manager --set-disable repository

You can also use a global regular expression to disable all matching software sources.

dnf config-manager --set-disable glob_expression

Managing Software Package

The DNF enables you to query, install, and delete software packages.

Searching for Software Packages

You can search for the required RPM package by its name, abbreviation, or description. The command is as follows:

dnf search term

The following is an example:

$   dnf search httpd
========================================== N/S matched: httpd ==========================================
httpd.aarch64 : Apache HTTP Server
httpd-devel.aarch64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.aarch64  : Tools for use with the Apache HTTP Server
libmicrohttpd.aarch64  : Lightweight library for embedding a webserver in applications
mod_auth_mellon.aarch64  : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.aarch64  : Apache httpd module for Subversion server

Listing Software Packages

To list all installed and available RPM packages in the system, run the following command:

dnf list all

To list a specific RPM package in the system, run the following command:

dnf list glob_expression...

The following is an example:

$ dnf list httpd
Available Packages
httpd.aarch64              2.4.34-8.h5.oe1           Local

Displaying RPM Package Information

To view information about one or more RPM packages, run the following command:

dnf info package_name...

The following is a command example:

$ dnf info httpd
Available Packages
Name        : httpd
Version     : 2.4.34
Release     : 8.h5.oe1
Arch        : aarch64
Size        : 1.2 M
Repo        : Local
Summary     : Apache HTTP Server
URL         : http://httpd.apache.org/
License     : ASL 2.0
Description : The Apache HTTP Server is a powerful, efficient, and extensible
            : web server.

Installing an RPM Package

To install a software package and all its dependencies that have not been installed, run the following command as the user root:

dnf install package_name

You can also add software package names to install multiple software packages at the same time. Add the strict=False parameter to the /etc/dnf/dnf.conf configuration file and run the dnf command to add –setopt=strict=0. Run the following command as the user root:

dnf install package_name package_name... --setopt=strict=0

The following is an example:

# dnf install httpd

NOTE:

Downloading Software Packages

To download the software package using the DNF, run the following command as the user root:

dnf download package_name

If you need to download the dependency packages that are not installed, add --resolve. The command is as follows:

dnf download --resolve package_name

The following is an example:

# dnf download --resolve httpd

Deleting a Software Package

To uninstall the software package and related dependent software packages, run the following command as the user root:

dnf remove package_name...

The following is an example:

# dnf remove totem

Managing Software Package Groups

A software package set is a group of software packages that serve a common purpose, for example, a system tool set. You can use the DNF to install or delete software package groups, improving operation efficiency.

Listing Software Package Groups

The summary parameter can be used to list the number of all installed software package groups, available groups, and available environment groups in the system. The command is as follows:

dnf groups summary

The following is an example:

# dnf groups summary
Last metadata expiration check: 0:11:56 ago on Sat 17 Aug 2019 07:45:14 PM CST.
Available Groups: 8

To list all software package groups and their group IDs, run the following command:

dnf group list

The following is an example:

# dnf group list
Last metadata expiration check: 0:10:32 ago on Sat 17 Aug 2019 07:45:14 PM CST.
Available Environment Groups:
   Minimal Install
   Custom Operating System
   Server
Available Groups:
   Development Tools
   Graphical Administration Tools
   Headless Management
   Legacy UNIX Compatibility
   Network Servers
   Scientific Support
   Security Tools
   System Tools

Displaying the Software Package Group Information

To list the mandatory and optional packages contained in a software package group, run the following command:

dnf group info glob_expression...

The following is an example of displaying the Development Tools information:

# dnf group info "Development Tools"
Last metadata expiration check: 0:14:54 ago on Wed 05 Jun 2019 08:38:02 PM CST.

Group: Development Tools
 Description: A basic development environment.
 Mandatory Packages:
   binutils
   glibc-devel
   make
   pkgconf
   pkgconf-m4
   pkgconf-pkg-config
   rpm-sign
 Optional Packages:
   expect

Installation Software Package Group

Each software package group has its own name and corresponding group ID. You can use the software package group name or its ID to install the software package.

To install a software package group, run the following command as the user root:

dnf group install group_name
dnf group install groupid

For example, to install the software package group of Development Tools, run the following command:

# dnf group install "Development Tools"
# dnf group install development

Deleting a Software Package Group

To uninstall a software package group, you can use the group name or ID to run the following command as the user root:

dnf group remove group_name
dnf group remove groupid

For example, to delete the software package group of Development Tools, run the following command:

# dnf group remove "Development Tools"
# dnf group remove development

Check and Update

You can use the DNF to check whether any software package in your system needs to be updated. You can use the DNF to list the software packages to be updated. You can choose to update all packages at a time or update only specified packages.

Checking for Update

To list all currently available updates, run the following command:

dnf check-update

The following is an example:

# dnf check-update
Last metadata expiration check: 0:02:10 ago on Sun 01 Sep 2019 11:28:07 PM  CST.

anaconda-core.aarch64       19.31.123-1.14             updates
anaconda-gui.aarch64        19.31.123-1.14             updates
anaconda-tui.aarch64        19.31.123-1.14             updates
anaconda-user-help.aarch64  19.31.123-1.14             updates
anaconda-widgets.aarch64    19.31.123-1.14             updates
bind-libs.aarch64           32:9.9.4-29.3              updates
bind-libs-lite.aarch64      32:9.9.4-29.3              updates
bind-license.noarch         32:9.9.4-29.3              updates
bind-utils.aarch64          32:9.9.4-29.3              updates
...

Upgrade

To upgrade a single software package, run the following command as the user root:

dnf update package_name

For example, to upgrade the RPM package, run the following command:

# dnf update anaconda-gui.aarch64
Last metadata expiration check: 0:02:10 ago on Sun 01 Sep 2019 11:30:27 PM  CST.
Dependencies Resolved
================================================================================
 Package                  Arch         Version              Repository     Size
================================================================================
Updating:
 anaconda-gui             aarch64      19.31.123-1.14       updates       461 k
 anaconda-core            aarch64      19.31.123-1.14       updates       1.4 M
 anaconda-tui             aarch64      19.31.123-1.14       updates       274 k
 anaconda-user-help       aarch64      19.31.123-1.14       updates       315 k
 anaconda-widgets         aarch64      19.31.123-1.14       updates       748 k

Transaction Summary
================================================================================
Upgrade  5 Package

Total download size: 3.1 M
Is this ok [y/N]:

Similarly, to upgrade a software package group, run the following command as the user root:

dnf group update group_name

Updating All Packages and Their Dependencies

To update all packages and their dependencies, run the following command as the user root:

dnf update

Bug Catching

Buggy Content

Bug Description

Submit As Issue

It's a little complicated....

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Bug Type
Specifications and Common Mistakes

● Misspellings or punctuation mistakes;

● Incorrect links, empty cells, or wrong formats;

● Chinese characters in English context;

● Minor inconsistencies between the UI and descriptions;

● Low writing fluency that does not affect understanding;

● Incorrect version numbers, including software package names and version numbers on the UI.

Usability

● Incorrect or missing key steps;

● Missing prerequisites or precautions;

● Ambiguous figures, tables, or texts;

● Unclear logic, such as missing classifications, items, and steps.

Correctness

● Technical principles, function descriptions, or specifications inconsistent with those of the software;

● Incorrect schematic or architecture diagrams;

● Incorrect commands or command parameters;

● Incorrect code;

● Commands inconsistent with the functions;

● Wrong screenshots.

Risk Warnings

● Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

● Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions;

● Copyright infringement.

How satisfied are you with this document

Not satisfied at all
Very satisfied
Submit
Click to create an issue. An issue template will be automatically generated based on your feedback.