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=FalseCommon options are as follows:
Table 1 main parameter description
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:
text[repository] name=repository_name baseurl=repository_url**NOTE:**
openEuler provides an online image source at https://repo.openeuler.org/. For example, if the openEuler 22.03 LTS SP4 version is aarch64, the baseurl can be set to https://repo.openeuler.org/openEuler-22.03-LTS-SP4/OS/aarch64/.
Common options are as follows:
Table 2 repository parameter description
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 Installing the OS.
For example, run the following command as the root user to add the openeuler repo source to the openEuler.repo file.
bashvi /etc/yum.repos.d/openEuler.repotext[OS] name=openEuler-$releasever - OS baseurl=http://repo.openeuler.org/openEuler-22.03-LTS-SP4/OS/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://repo.openeuler.org/openEuler-22.03-LTS-SP4/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:
bashdnf config-manager --dumpTo display the configuration of a software source, query the repo id:
bashdnf repolistRun the following command to display the software source configuration of the corresponding ID. In the command, repository indicates the repository ID.
bashdnf config-manager --dump repositoryYou can also use a global regular expression to display all matching configurations.
bashdnf config-manager --dump glob_expression
Creating a Local Software Repository
To create a local repository of software sources, perform the following steps.
Install the createrepo software package. Run the following command as the root user:
bashdnf install createrepoCopy the required software packages to a directory, for example, /mnt/local_repo/.
Run the following command to create a software source:
bashcreaterepo /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_urlEnabling 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 repositoryYou 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_expressionDisabling a Software Repository
To disable a software source, run the following command as the user root:
dnf config-manager --set-disable repositoryYou can also use a global regular expression to disable all matching software sources.
dnf config-manager --set-disable glob_expressionManaging 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 termThe 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 serverListing Software Packages
To list all installed and available RPM packages in the system, run the following command:
dnf list allTo 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.51-17.oe2203SP4 LocalDisplaying 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.51
Release : 17.oe2203SP4
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_nameYou 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=0The following is an example:
dnf install httpd**NOTE:**
- If the RPM package fails to be installed, see Installation Failure Caused by Software Package Conflict, File Conflict, or Missing Software Package.
- Do not install the install-scripts software package. This software package is used by imageTailor for tailoring ISO images. openEuler will fail to boot if install-scripts is installed.
Downloading Software Packages
To download the software package using the DNF, run the following command as the user root:
dnf download package_nameIf you need to download the dependency packages that are not installed, add --resolve. The command is as follows:
dnf download --resolve package_nameThe following is an example:
dnf download --resolve httpdDeleting 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 totemManaging 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 summaryThe 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: 8To list all software package groups and their group IDs, run the following command:
dnf group listThe 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
```bash
### Displaying the Software Package Group Information
To list the mandatory and optional packages contained in a software package group, run the following command:
```bash
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:
expectInstallation 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_nameor
dnf group install groupidFor example, to install the software package group of Development Tools, run the following command:
dnf group install "Development Tools"or
dnf group install developmentDeleting 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_namednf group remove groupidFor example, to delete the software package group of Development Tools, run the following command:
dnf group remove "Development Tools"dnf group remove developmentCheck 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-updateThe following is an example:
$ dnf check-update
Last metadata expiration check: 0:02:10 ago on Sun 21 May 2023 11:28:07 PM CST.
anaconda-core.aarch64 36.15.5-17.oe2203SP4 update
anaconda-tui.aarch64 36.15.5-17.oe2203SP4 update
anaconda-user-help.aarch64 26.1-10.oe2203SP4 update
bind-libs.aarch64 9.16.23-18.oe2203SP4 update
bind-license.noarch 9.16.23-18.oe2203SP4 update
bind-utils.aarch64 9.16.23-18.oe2203SP4 updatey
...Upgrade
To upgrade a single software package, run the following command as the user root:
dnf update package_nameFor 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_nameUpdating All Packages and Their Dependencies
To update all packages and their dependencies, run the following command as the user root:
dnf update