26 DNF Command Examples for Package Management in Fedora Linux

Fedora-Linux-DNF-commands

DNF or Dandified YUM is a fork of YUM package manager. It was introduced in fedora 18 & on fedora 22, it has now become default package manager for handling the RPM packages.

DNF resolves all the problems that has been associated with yum, like poor performance, high memory usage, slowness for dependency resolution. DNF can be termed as the next major version of the YUM package manager. Currently, the most stable version of DNF is version 2.6.3

In this tutorial, we will discuss the DNF commands used for package management. This article will serve as a cheat sheet for DNF. So let’s start …..

DNF Command

The syntax for using DNF command is pretty similar to using YUM, so you will find lots of similarity between the two commands.

Example:1) List enabled repositories

To list all the enabled repositories on the system, run

[[email protected] ~]$ sudo dnf repolist
[sudo] password for linuxtechi:
Last metadata expiration check: 2 days, 23:21:54 ago on Thu 10 Oct 2017 10:09:05 AM IST.
repo id                  repo name                                             status
*epel                   Extra Packages for Enterprise Linux 7 - x86_64         11,989
*fedora                 Fedora 26 - x86_64                                     53,912
*updates                Fedora 26 - x86_64 - Updates                           9,405
virtualbox              Fedora 26 - x86_64 - VirtualBox                        10
[[email protected] ~]$

Example:2) List all repositories (enabled as well as disabled)

If we need to see all the repositories that are either enabled or disabled, we need to run following

[[email protected] ~]$ sudo dnf repolist all

dnf-repolist-all-command

Example:3) Installing a package

Like yum, we use ‘install‘ option followed by package name with dnf to install, Let’s suppose we want to install web server package (httpd)

[[email protected] ~]$ sudo dnf install httpd

dnf-install-command-output

Example:4) Removing a package

To remove a package, execute the following from terminal,

[[email protected] ~]$ sudo dnf remove httpd

or

[[email protected] ~]$ sudo dnf erase httpd

Output of above command would be something like below:

dnf-remove-package-command

Example:5) Update a package

Run the following command to update a single package on the system,

Syntax: dnf update {pkg-name}

[[email protected] ~]$ sudo dnf update filezilla

Example:6) Check for full system update

For a system wide update check, execute the following command,

[[email protected] ~]$ sudo dnf check-update

DNF-check-Update-command

Example:7) Upgrade all system packages

To upgrade all system packages, run the following

[[email protected] ~]$ sudo dnf upgrade

DNF-Upgrade-command

Example:8) List all group packages

Use the following to list all group packages

[[email protected] ~]$ sudo dnf grouplist
Last metadata expiration check: 1:40:19 ago on Tue 10 Oct 2017 10:08:39 AM IST.
Available Environment Groups:
   Fedora Custom Operating System
   Minimal Install
   Fedora Server Edition
   Fedora Workstation
   Fedora Cloud Server
   KDE Plasma Workspaces
   Xfce Desktop
   LXDE Desktop
   Hawaii Desktop
   LXQt Desktop
   Cinnamon Desktop
   MATE Desktop
   Sugar Desktop Environment
   Development and Creative Workstation
   Web Server
   Infrastructure Server
   Basic Desktop
Installed Groups:
   LibreOffice
Available Groups:
   3D Printing
   Administration Tools
   Ansible node
   Audio Production
…………………

Example:9) Installing Group packages

Similar packages are grouped together & can be installed from single command, rather than using separate commands. To install a group, run

[[email protected] ~]$ sudo dnf groupinstall "Development Tools"

dnf-groupintsall-command

Example:10) Removing group packages

To remove a complete group of packages from system, run the following dnf command,

Syntax:  dnf groupremove ‘group_name’

[[email protected] ~]$ sudo dnf groupremove "Development Tools"

We can also use ‘groupupdate’ for updating the group packages as well.

Example:11) Search for packages

To look for a particular package from the repositories, execute

Syntax: dnf search {package_name}

Let’s suppose I want to search net-tools package

[[email protected] ~]$ sudo dnf search net-tools
Last metadata expiration check: 1 day, 21:48:35 ago on Tue 10 Oct 2017 10:08:39 AM IST.
=================== Name Exactly Matched: net-tools ===================
net-tools.x86_64 : Basic networking tools
[[email protected] ~]$

Example:12) Download (don’t not install) a package

There can some scenarios where we require to download the packages but don’t wish to install. Use the following command to download package like samba

Syntax : dnf download package_name

[[email protected] ~]$ sudo dnf download samba
Last metadata expiration check: 0:03:54 ago on Thu 12 Oct 2017 08:00:21 AM IST.

samba-4.6.8-0.fc26.x86_64.rpm          139 kB/s | 636 kB     00:04

[[email protected] ~]$

Example:13) Show all available packages

To get list of all available packages from repositories, open terminal & run beneath dnf command

[[email protected] ~]$ dnf list available | more

dnf-list-available-command

Example:14) Show only installed packages

Now, if we only require a list of installed packages on the system, we can get it by executing following command,

[[email protected] ~]$ dnf list installed

dnf-list-installed-packages-command

Example:15) Show all installed as well as available packages

To get list of all packages i.e. installed as well as available, run the following command

[[email protected] ~]$ dnf list

dnf-list-command

Example:16) Enable repo for installation

To use a particular repository for installing a package, run

[[email protected] ~]$ sudo dnf install --enablerepo=epel mysql

Extra Packages for Enterprise Linux 7 - x86_64         3.9 MB/s |  13 MB     00:03

Last metadata expiration check: 0:00:07 ago on Thu 12 Oct 2017 09:53:00 AM IST.

Dependencies resolved.

===========================================================================================
 Package                 Arch       Version           Repository        Size
===========================================================================================

Installing:

 mariadb                 x86_64      3:10.1.26-2.fc26    updates         6.4 M

Installing dependencies:

 mariadb-common          x86_64      3:10.1.26-2.fc26    updates         100 k

 mariadb-config          x86_64      3:10.1.26-2.fc26    updates         33 k

 mariadb-libs            x86_64      3:10.1.26-2.fc26    updates         663 k
Transaction Summary
============================================================================================
Total download size: 7.2 M
Installed size: 44 M
Is this ok [y/N]: y

Example:17) Check which package provides the required function

If we wants to know which package is responsible for getting a particular functionality, like we need to know package name that is associated with ‘crontab’ or with some other command, than we can use the dnf command ‘provides‘ option in the following manner,

[[email protected] ~]$ sudo dnf provides crontab
Last metadata expiration check: 0:02:44 ago on Thu 12 Oct 2017 09:53:00 AM IST.

cronie-1.5.1-5.fc26.x86_64 : Cron daemon for executing programs at set times

Repo        : @System

cronie-1.5.1-5.fc26.x86_64 : Cron daemon for executing programs at set times

Repo        : fedora
[[email protected] ~]$

Same can be done against a file, we can also use the same command with a file location to get the package name with which the file is associated,

[[email protected]]$ sudo dnf provides /var/www/html

Example:18) View package information

To get details of a specific package, execute

[[email protected] ~]$ dnf info cronie
Last metadata expiration check: 0:00:20 ago on Thu 12 Oct 2017 09:56:28 AM IST.
Installed Packages
Name         : cronie
Version      : 1.5.1
Release      : 5.fc26
Arch         : x86_64
Size         : 236 k
Source       : cronie-1.5.1-5.fc26.src.rpm
Repo         : @System
From repo    : anaconda
Summary      : Cron daemon for executing programs at set times
URL          : https://fedorahosted.org/cronie
License      : MIT and BSD and ISC and GPLv2+
Description  : Cronie contains the standard UNIX daemon crond that runs specified programs at
             : scheduled times and related tools. It is a fork of the original vixie-cron and
             : has security and configuration enhancements like the ability to use pam and
             : SELinux.
[[email protected] ~]$

Example:19) Building a cache

Though the cache is built automatically over time but we also have an option to manually build the cache, so that the future actions are fast & completed quickly. To create a cache manually, execute

[[email protected] ~]$ sudo time dnf makecache
Last metadata expiration check: 0:04:41 ago on Thu 12 Oct 2017 09:53:00 AM IST.
Metadata cache created.
0.86user 0.12system 0:01.04elapsed 95%CPU (0avgtext+0avgdata 106872maxresident)k
0inputs+1192outputs (0major+39606minor)pagefaults 0swaps
[[email protected] ~]$

Example:20) Delete a cache

To delete all the dnf cached data, execute the following commands

[[email protected] ~]$ sudo dnf clean all
34 files removed
[[email protected] ~]$

Example:21) Check the transaction history

To check all the transactions that have been done using DNF command, run the following commands

[[email protected] ~]$ sudo dnf history

dnf-history-command

It will produce a list of all transactions in order as they have occurred with a corresponding number. We can use this number to further get the details of that transaction,

[[email protected] ~]$ sudo dnf history info 5

dnf-history-info-command

Logs related to installation, removal or updates are kept in the log file /var/log/dnf.log, Using dnf history command we can also rollback the system updates.

Example:22) Removing orphan packages

Orphan packages are those packages that were once installed to satisfy dependency for some other package but are not required now. To remove such packages, run

[[email protected] ~]$ sudo dnf autoremove

dnf-autoremove-command

Example:23) Synchronize all the packages to latest stable releases

Run the following command in order to synchronize all the packages to latest stable releases,

[[email protected] ~]$ sudo dnf distro-sync

dnf-distro-sync-command

If we need to sync only a single package, mention that package_name at the end otherwise all the packages will be synced.

Example:24) Reinstall a package

To reinstall a package, if need be, run the following command,

[[email protected] ~]$ sudo dnf reinstall postfix
Last metadata expiration check: 0:07:26 ago on Thu 12 Oct 2017 10:09:05 AM IST.
Dependencies resolved.
===========================================================================
 Package         Arch        Version            Repository      Size
===========================================================================
Reinstalling:

 postfix         x86_64       2:3.2.2-1.fc26    fedora           1.4 M

Transaction Summary
===========================================================================
Total download size: 1.4 M
Is this ok [y/N]: y

Example:25) Upgrade to a particular version

With DNF, its also possible to upgrade the rpm package to a particular version, to achieve this run the following command,

[[email protected] ~]$ sudo dnf upgrade-to httpd-2.4.27-3.fc26

Example:26) Get list of all DNF commands and options

To get a list of all the available options that can be used with DNF, run

[[email protected] ~]$ dnf help

dnf-help-command

This was our complete tutorial for DNF package manager with examples. Please do leave any queries or questions you have for this tutorial in the comments below.

4 Responses

  1. Jehosha says:

    Every parameter I run with dnf command gives me the following error message:
    Error: Failed to synchronize cache for repo ‘updates’

    I have a brand new Fedora 27 installed, but cannot move on for this error.

  2. Rick McKinney says:

    Hello Pradeep Kumar.

    If only I had access to your knowledge, what a joy my Fedora 30 installation would have been. I am relatively new to the intricacies to Linux. I came to Fedora 30 from Ubuntu, most recently 19.04. Both distros have much to offer.

    I do not know why, but Fedora seems more difficult to me. Perhaps it’s just getting the hang of its nuances.

    I seek your counsel on one niggly problem I am currently having: trying to get Synaptic Package Manager to run on Fedora 30. From the Terminal, I enter sudo -s and provide the password when prompted. This is a carryover from Ubuntu.

    Next, dnf install synaptic runs perfectly well and is available in the applications after installation is complete.

    Now the problem: Synaptic starts just fine. But then, it prompts for ROOT’s password?!?!

    I’ve tried with my sudo -s password. No joy.

    Please, could you provide some guidance to help me overcome this problem? I should be most grateful.

    Thank you very much for your consideration.

    Rick

  3. John N Rayner says:

    Very helpful but reinstall for a group not included. I am using MATE but it suddenly produced errors, e.g. “man package” leaves off first characters in the lines. Assume this is not a bug so am trying to reinstall “MATE Desktop” Other Desktops do not reproduce this error. Suggestions? Using Fedora 30 – up-to-date.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest