dnf package manager examples

dnf package manager examples

dnf title

Introduction

DNF is considered to become the replacement for yum as the next default package manager for yum.
The dnf package manager was introduced with Fedora 18 and had been designated as the default package manager as of Fedora 22.

DNF has the following advantages over its predecessor yum:

  • Provides faster dependency resolution for packages with lesser memory usage as compared to yum.
  • Its usage syntax is similar to that of yum so there’s no steep learning curve.
  • Provides specific and detailed documentation regarding Python API.
  • Execute parallel package management operaions.
  • Runs in both Python 2 and Python 3 environments.

We would like to point out that dnf lacks some of the options included in yum. Although it does comprise of all the features that would be required by a normal user to install and remove packages.In this article, we will explain how to install and use dnf package management software on your system.

 

DNF installation
The dnf package along with its dependencies used to be available in the EPEL repository as of this writing. However, the package has been removed from the EPEL repository due to some security flaws. A replacement has not been added to the EPEl repository yet. Therefore, we will use wget to manually download the dnf package manager .rpm file along with its dependencies and install them on our Centos 7.3 system.


[root@linuxnix ~]# wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-conf-0.6.4-2.sdl7.noarch.rpm
--2017-12-10 21:59:38-- http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-conf-0.6.4-2.sdl7.noarch.rpm
Resolving springdale.math.ias.edu (springdale.math.ias.edu)... 192.16.204.192
Connecting to springdale.math.ias.edu (springdale.math.ias.edu)|192.16.204.192|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 62404 (61K) [application/x-rpm]
Saving to: ‘dnf-conf-0.6.4-2.sdl7.noarch.rpm’

100%[==========================================================================================>] 62,404 67.7KB/s in 0.9s

2017-12-10 21:59:40 (67.7 KB/s) - ‘dnf-conf-0.6.4-2.sdl7.noarch.rpm’ saved [62404/62404]

[root@linuxnix ~]# wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64//dnf-0.6.4-2.sdl7.noarch.rpm
--2017-12-10 21:59:49-- http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64//dnf-0.6.4-2.sdl7.noarch.rpm
Resolving springdale.math.ias.edu (springdale.math.ias.edu)... 192.16.204.192
Connecting to springdale.math.ias.edu (springdale.math.ias.edu)|192.16.204.192|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 213696 (209K) [application/x-rpm]
Saving to: ‘dnf-0.6.4-2.sdl7.noarch.rpm’

100%[==========================================================================================>] 213,696 8.79KB/s in 39s

2017-12-10 22:00:32 (5.34 KB/s) - ‘dnf-0.6.4-2.sdl7.noarch.rpm’ saved [213696/213696]

[root@linuxnix ~]#
[root@linuxnix ~]# wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/python-dnf-0.6.4-2.sdl7.noarch.rpm
--2017-12-10 22:00:34-- http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/python-dnf-0.6.4-2.sdl7.noarch.rpm
Resolving springdale.math.ias.edu (springdale.math.ias.edu)... 192.16.204.192
Connecting to springdale.math.ias.edu (springdale.math.ias.edu)|192.16.204.192|:80...
connected.
HTTP request sent, awaiting response... 200 OK
Length: 416988 (407K) [application/x-rpm]
Saving to: ‘python-dnf-0.6.4-2.sdl7.noarch.rpm’

100%[==========================================================================================>] 416,988 10.5KB/s in 32s

2017-12-10 22:01:07 (12.8 KB/s) - ‘python-dnf-0.6.4-2.sdl7.noarch.rpm’ saved [416988/416988]

[root@linuxnix ~]#


Now that we have the packages downloaded and available locally on our system, we will use yum localinstall to install them as shown in the following command:

[root@linuxnix ~]# yum localinstall python-dnf-0.6.4-2.sdl7.noarch.rpm dnf-0.6.4-2.sdl7.noarch.rpm dnf-conf-0.6.4-2.sdl7.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining python-dnf-0.6.4-2.sdl7.noarch.rpm: python-dnf-0.6.4-2.sdl7.noarch
Marking python-dnf-0.6.4-2.sdl7.noarch.rpm to be installed
Examining dnf-0.6.4-2.sdl7.noarch.rpm: dnf-0.6.4-2.sdl7.noarch
Marking dnf-0.6.4-2.sdl7.noarch.rpm to be installed
Examining dnf-conf-0.6.4-2.sdl7.noarch.rpm: dnf-conf-0.6.4-2.sdl7.noarch
Marking dnf-conf-0.6.4-2.sdl7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package dnf.noarch 0:0.6.4-2.sdl7 will be installed
---> Package dnf-conf.noarch 0:0.6.4-2.sdl7 will be installed
---> Package python-dnf.noarch 0:0.6.4-2.sdl7 will be installed
--> Processing Dependency: python-hawkey >= 0.5.3 for package: python-dnf-0.6.4-2.sdl7.noarch
Loading mirror speeds from cached hostfile
* base: centos.mirror.net.in
* epel: epel.mirror.angkasa.id
* extras: mirror.digistar.vn
* updates: mirrors.123host.vn
--> Processing Dependency: python-libcomps >= 0.1.6 for package: python-dnf-0.6.4-2.sdl7.noarch
--> Processing Dependency: python-librepo >= 1.7.5 for package: python-dnf-0.6.4-2.sdl7.noarch
--> Processing Dependency: deltarpm for package: python-dnf-0.6.4-2.sdl7.noarch
--> Running transaction check
---> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
---> Package python-librepo.x86_64 0:1.7.16-1.el7 will be installed
--> Processing Dependency: librepo(x86-64) = 1.7.16-1.el7 for package: python-librepo-1.7.16-1.el7.x86_64
--> Processing Dependency: librepo.so.0()(64bit) for package: python-librepo-1.7.16-1.el7.x86_64
---> Package python2-hawkey.x86_64 0:0.6.3-4.el7 will be installed
--> Processing Dependency: hawkey(x86-64) = 0.6.3-4.el7 for package: python2-hawkey-0.6.3-4.el7.x86_64
--> Processing Dependency: libsolvext.so.0(SOLV_1.0)(64bit) for package: python2-hawkey-0.6.3-4.el7.x86_64
--> Processing Dependency: libsolv.so.0(SOLV_1.0)(64bit) for package: python2-hawkey-0.6.3-4.el7.x86_64
--> Processing Dependency: libsolvext.so.0()(64bit) for package: python2-hawkey-0.6.3-4.el7.x86_64
--> Processing Dependency: libsolv.so.0()(64bit) for package: python2-hawkey-0.6.3-4.el7.x86_64
--> Processing Dependency: libhawkey.so.2()(64bit) for package: python2-hawkey-0.6.3-4.el7.x86_64
---> Package python2-libcomps.x86_64 0:0.1.8-3.el7 will be installed
--> Processing Dependency: libcomps(x86-64) = 0.1.8-3.el7 for package: python2-libcomps-0.1.8-3.el7.x86_64
--> Processing Dependency: libcomps.so.0.1.6()(64bit) for package: python2-libcomps-0.1.8-3.el7.x86_64
--> Running transaction check
---> Package hawkey.x86_64 0:0.6.3-4.el7 will be installed
---> Package libcomps.x86_64 0:0.1.8-3.el7 will be installed
---> Package librepo.x86_64 0:1.7.16-1.el7 will be installed
---> Package libsolv.x86_64 0:0.6.26-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
dnf noarch 0.6.4-2.sdl7 /dnf-0.6.4-2.sdl7.noarch 652 k
dnf-conf noarch 0.6.4-2.sdl7 /dnf-conf-0.6.4-2.sdl7.noarch 29 k
python-dnf noarch 0.6.4-2.sdl7 /python-dnf-0.6.4-2.sdl7.noarch 1.8 M
Installing for dependencies:
deltarpm x86_64 3.6-3.el7 base 82 k
hawkey x86_64 0.6.3-4.el7 base 89 k
libcomps x86_64 0.1.8-3.el7 epel 74 k
librepo x86_64 1.7.16-1.el7 base 77 k
libsolv x86_64 0.6.26-1.el7 base 323 k
python-librepo x86_64 1.7.16-1.el7 base 49 k
python2-hawkey x86_64 0.6.3-4.el7 base 73 k
python2-libcomps x86_64 0.1.8-3.el7 epel 46 k

Transaction Summary
================================================================================
Install 3 Packages (+8 Dependent packages)

Total size: 3.2 M
Total download size: 812 k
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): hawkey-0.6.3-4.el7.x86_64.rpm | 89 kB 00:00:09
(2/8): deltarpm-3.6-3.el7.x86_64.rpm | 82 kB 00:00:11
(3/8): librepo-1.7.16-1.el7.x86_64.rpm | 77 kB 00:00:12
(4/8): python2-hawkey-0.6.3-4.el7.x86_64.rpm | 73 kB 00:00:01
(5/8): python-librepo-1.7.16-1.el7.x86_64.rpm | 49 kB 00:00:04
(6/8): libsolv-0.6.26-1.el7.x86_64.rpm | 323 kB 00:00:17
(7/8): python2-libcomps-0.1.8-3.el7.x86_64.rpm | 46 kB 00:00:07
(8/8): libcomps-0.1.8-3.el7.x86_64.rpm | 74 kB 00:00:20
------------------------------------------------------------------------------------------------------------------------------------
Total 39 kB/s | 812 kB 00:00:20
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libsolv-0.6.26-1.el7.x86_64 1/11
Installing : hawkey-0.6.3-4.el7.x86_64 2/11
Installing : python2-hawkey-0.6.3-4.el7.x86_64 3/11
Installing : deltarpm-3.6-3.el7.x86_64 4/11
Installing : libcomps-0.1.8-3.el7.x86_64 5/11
Installing : python2-libcomps-0.1.8-3.el7.x86_64 6/11
Installing : dnf-conf-0.6.4-2.sdl7.noarch 7/11
Installing : librepo-1.7.16-1.el7.x86_64 8/11
Installing : python-librepo-1.7.16-1.el7.x86_64 9/11
Installing : python-dnf-0.6.4-2.sdl7.noarch 10/11
Installing : dnf-0.6.4-2.sdl7.noarch 11/11
Verifying : libsolv-0.6.26-1.el7.x86_64 1/11
Verifying : python2-libcomps-0.1.8-3.el7.x86_64 2/11
Verifying : librepo-1.7.16-1.el7.x86_64 3/11
Verifying : dnf-conf-0.6.4-2.sdl7.noarch 4/11
Verifying : python-dnf-0.6.4-2.sdl7.noarch 5/11
Verifying : libcomps-0.1.8-3.el7.x86_64 6/11
Verifying : python2-hawkey-0.6.3-4.el7.x86_64 7/11
Verifying : python-librepo-1.7.16-1.el7.x86_64 8/11
Verifying : deltarpm-3.6-3.el7.x86_64 9/11
Verifying : hawkey-0.6.3-4.el7.x86_64 10/11
Verifying : dnf-0.6.4-2.sdl7.noarch 11/11

Installed:
dnf.noarch 0:0.6.4-2.sdl7 dnf-conf.noarch 0:0.6.4-2.sdl7 python-dnf.noarch 0:0.6.4-2.sdl7

Dependency Installed:
deltarpm.x86_64 0:3.6-3.el7 hawkey.x86_64 0:0.6.3-4.el7 libcomps.x86_64 0:0.1.8-3.el7
librepo.x86_64 0:1.7.16-1.el7 libsolv.x86_64 0:0.6.26-1.el7 python-librepo.x86_64 0:1.7.16-1.el7
python2-hawkey.x86_64 0:0.6.3-4.el7 python2-libcomps.x86_64 0:0.1.8-3.el7

Complete!
[root@linuxnix ~]#

Let’s check the version of the dnf package manager

[root@linuxnix ~]# dnf --version
0.6.4
Installed: dnf-0:0.6.4-2.sdl7.noarch at 2017-12-10 16:33
Built : at 2016-10-09 17:18
Installed: rpm-0:4.11.3-21.el7.x86_64 at 2017-05-15 09:26
Built : CentOS BuildSystem  at 2016-11-05 23:37
[root@linuxnix ~]#

This method installs a very old version of the dnf package manager as compared to the latest one available.
The purpose of this manual installation was to show you how to install dnf on a CentOS system when the dnf package was not available in any of the repositories. For, all the examples that we will be working on, we will use a freshly installed Fedora 26 system which has the latest version of dnf installed.

We will now go through some examples to demonstrate the most commonly used features of dnf.

Example 1: Verify dnf version
To do this we use the dnf –version command.

[root@linuxnix ~]# dnf --version
2.5.1
Installed: dnf-0:2.5.1-1.fc26.noarch at Sun 10 Dec 2017 12:42:52 PM GMT
Built : Fedora Project at Mon 12 Jun 2017 12:39:07 PM GMT
Installed: rpm-0:4.13.0.1-4.fc26.x86_64 at Sun 10 Dec 2017 12:42:43 PM GMT
Built : Fedora Project at Tue 25 Apr 2017 08:07:10 PM GMT

Example 2: Install a package
To install a package using the dnf package manager we use the dnf install command followed by the package name.
To demonstrate, let’s install the tmux package.

 

[root@linuxnix ~]# dnf install tmux
Last metadata expiration check: 0:50:43 ago on Sun 10 Dec 2017 05:08:39 AM PST.
Dependencies resolved.
=========================================================================
Package Arch Version Repository Size
=========================================================================
Installing:
tmux x86_64 2.5-4.fc26 updates 297 k

Transaction Summary
=========================================================================
Install 1 Package

Total download size: 297 k
Installed size: 694 k
Is this ok [y/N]: y
Downloading Packages:
tmux-2.5-4.fc26.x86_64.rpm 14 kB/s | 297 kB 00:21
------------------------------------------------------------------------------------------------------------------------------------
Total 12 kB/s | 297 kB 00:24
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : tmux-2.5-4.fc26.x86_64 1/1
Running scriptlet: tmux-2.5-4.fc26.x86_64 1/1
Verifying : tmux-2.5-4.fc26.x86_64 1/1

Installed:
tmux.x86_64 2.5-4.fc26
Complete!
[root@linuxnix ~]#

Example 3: Remove a package
To remove a package, we use the dnf remove command.
We’ll demonstrate this by removing the tmux package we installed in the previous example.

[root@linuxnix ~]# dnf remove tmux
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
tmux x86_64 2.5-4.fc26 @updates 694 k

Transaction Summary
================================================================================
Remove 1 Package

Freed space: 694 k
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Erasing : tmux-2.5-4.fc26.x86_64 1/1
Running scriptlet: tmux-2.5-4.fc26.x86_64 1/1
Verifying : tmux-2.5-4.fc26.x86_64 1/1

Removed:
tmux.x86_64 2.5-4.fc26

Example 4: Get information about a package
To obtain information about a package, use the dnf info command followed by the package name.
Let’s query dnf for information about the tmux package.

[root@linuxnix ~]# dnf info tmux
Last metadata expiration check: 0:54:46 ago on Sun 10 Dec 2017 05:08:39 AM PST.
Available Packages
Name : tmux
Version : 2.5
Release : 4.fc26
Arch : x86_64
Size : 297 k
Source : tmux-2.5-4.fc26.src.rpm
Repo : updates
Summary : A terminal multiplexer
URL : https://tmux.github.io/
License : ISC and BSD
Description : tmux is a "terminal multiplexer." It enables a number of terminals (or
: windows) to be accessed and controlled from a single terminal. tmux is
: intended to be a simple, modern, BSD-licensed alternative to programs such
: as GNU Screen.

Example 5: Update a package
To update a package, use the dnf update command followed the name of the package that you want to update.
Let’s update the bash shell on our system.

[root@linuxnix ~]# dnf update bash
Last metadata expiration check: 0:56:01 ago on Sun 10 Dec 2017 05:08:39 AM PST.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Upgrading:
bash x86_64 4.4.12-7.fc26 updates 1.5 M

Transaction Summary
================================================================================
Upgrade 1 Package

Total download size: 1.5 M
Is this ok [y/N]: y
Downloading Packages:
bash-4.4.12-7.fc26.x86_64.rpm 21 kB/s | 1.5 MB 01:16
------------------------------------------------------------------------------------------------------------------------------------
Total 18 kB/s | 1.5 MB 01:27
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : bash-4.4.12-7.fc26.x86_64 1/2
Running scriptlet: bash-4.4.12-7.fc26.x86_64 1/2
Cleanup : bash-4.4.12-5.fc26.x86_64 2/2
Running scriptlet: bash-4.4.12-5.fc26.x86_64 2/2
Verifying : bash-4.4.12-7.fc26.x86_64 1/2
Verifying : bash-4.4.12-5.fc26.x86_64 2/2
Upgraded:
bash.x86_64 4.4.12-7.fc26
Complete!

 

Example 6: Perform a system update
In order to update all installed packages to the latest versions available in the online repositories, use the dnf update command.

[root@linuxnix ~]# dnf update
Last metadata expiration check: 1:02:48 ago on Sun 10 Dec 2017 05:08:39 AM PST.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Upgrading:
GeoIP-GeoLite-data noarch 2017.10-1.fc26 updates 517 k
NetworkManager x86_64 1:1.8.2-1.fc26 updates 1.6 M
NetworkManager-libnm x86_64 1:1.8.2-1.fc26 updates 1.2 M
NetworkManager-team x86_64 1:1.8.2-1.fc26 updates 126 k
abrt x86_64 2.10.3-4.fc26 updates 517 k
abrt-addon-ccpp x86_64 2.10.3-4.fc26 updates 124 k
---------------------------------------------------------------output truncated for brevity

Example 7: Verify available repositories
To view the repositories from which dnf will install packages from, run the dnf repolist command.

[root@linuxnix ~]# dnf repolist
Last metadata expiration check: 1:04:18 ago on Sun 10 Dec 2017 05:08:39 AM PST.
repo id repo name status
*fedora Fedora 26 - x86_64 53,912
*updates Fedora 26 - x86_64 - Updates 11,562
[root@linuxnix ~]#

Example 8: Check which package provides a file
To query which package provides a file or binary, we use the dnf provides command followed by the file name.
Let’s check which package provides the ssh command.

[root@linuxnix ~]# dnf provides /usr/bin/ssh
Last metadata expiration check: 3:10:52 ago on Sun 10 Dec 2017 05:08:39 AM PST.
openssh-clients-7.5p1-2.fc26.x86_64 : An open source SSH client applications
Repo : @System
Matched from:
Filename : /usr/bin/ssh

openssh-clients-7.5p1-4.fc26.x86_64 : An open source SSH client applications
Repo : updates
Matched from:
Filename : /usr/bin/ssh

openssh-clients-7.5p1-2.fc26.x86_64 : An open source SSH client applications
Repo : fedora
Matched from:
Filename : /usr/bin/ssh

 

Example 9: Check dependencies of a package
To determine the dependency requirements for a package, we use the dnf depends command followed by the package name.
Let’s view dependencies for the tmux package that we installed in an earlier example.

[root@linuxnix ~]# dnf deplist tmux
Last metadata expiration check: 3:11:38 ago on Sun 10 Dec 2017 05:08:39 AM PST.
package: tmux-2.3-2.fc26.x86_64
dependency: /bin/sh
provider: bash-4.4.12-7.fc26.x86_64
dependency: libc.so.6(GLIBC_2.14)(64bit)
provider: glibc-2.25-12.fc26.x86_64
dependency: libevent-2.0.so.5()(64bit)
provider: libevent-2.0.22-3.fc26.x86_64
dependency: libncurses.so.6()(64bit)
provider: ncurses-libs-6.0-8.20170212.fc26.x86_64
dependency: libresolv.so.2()(64bit)
provider: glibc-2.25-12.fc26.x86_64
dependency: libresolv.so.2(GLIBC_2.2.5)(64bit)
provider: glibc-2.25-12.fc26.x86_64
dependency: libtinfo.so.6()(64bit)
provider: ncurses-libs-6.0-8.20170212.fc26.x86_64
dependency: libutempter.so.0()(64bit)
provider: libutempter-1.1.6-9.fc26.x86_64
dependency: libutempter.so.0(UTEMPTER_1.1)(64bit)
provider: libutempter-1.1.6-9.fc26.x86_64
dependency: libutil.so.1()(64bit)
provider: glibc-2.25-12.fc26.x86_64
dependency: libutil.so.1(GLIBC_2.2.5)(64bit)
provider: glibc-2.25-12.fc26.x86_64
dependency: rtld(GNU_HASH)
provider: glibc-2.25-12.fc26.i686
provider: glibc-2.25-12.fc26.x86_64

Example 10: Download a package without installing
To download a package without installing, we use the dnf download command followed by the name of the package we are interested in downloading.
In the below example, we’ll download the tmux package to the home directory of user sahil by specifying the –downloaddir option with the dnf download command.

[root@linuxnix ~]# dnf download tmux --downloaddir=/home/sahil
Last metadata expiration check: 3:13:35 ago on Sun 10 Dec 2017 05:08:39 AM PST.
tmux-2.5-4.fc26.x86_64.rpm 18 kB/s | 297 kB 00:16
[root@linuxnix ~]#

Conclusion

As you may have noticed from the above examples, the dnf package manager follows a very similar syntax to that of the yum package manager. Since we have already covered the features of the yum package manager in an earlier article, we’ll not be covering them in depth in this article. However, we do encourage you to explore the dnf package manager further and we are confident that we are likely to see more of dnf in the future.

The post dnf package manager examples appeared first on The Linux Juggernaut.

Administration dnf LinuxNix