×

Search anything:

Managing packages with yum/dnf in RHEL

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

Package management involves managing software on a system. This includes installing, upgrading, downgrading, updating, removing, etc. We discuss package management in Red Hat Enterprise Linux Distros using yum and dnf.

Table of contents.

  1. Introduction.
  2. Syntax.
  3. Commands.
  4. Differences between dnf and yum.
  5. Summary.
  6. References.

Introduction.

yum(Yellowdog Updater Modified) is the primary package manager for Red Hat Enterprise Linux distributions such as Rocky Linux, AlmaLinux, CentOS, Fedora, etc.
dnf(Dandified yum) is another package management tool for RHEL Linux distros. It is considered the next generation of its predecessor yum.

We will mostly use dnf however the same commands can be used with yum we shall learn the difference between the two shortly.

Syntax.

The syntax of the dnf command is as follows:

$ dnf [options] COMMAND

dnf1-1

Commands.

In this section, we look at commonly used yum/dnf commands.

1. Checking for updates.

Updating installed packages is a common task for Linux users. With yum we can check if there are any updates using the check-update option:

$ sudo yum check-update

dnf2

or by using dnf we write:

$ sudo dnf check-update

2. Updating packages

Now that we have checked for updates, we can install them as follows:

$ sudo dnf update

dnf3

In cases where we need to only update a single package we can update it as follows:

$ sudo dnf update [package name]

dnf4

We can also choose to exclude specific packages using the exclude of -x option as follows:

$ sudo dnf update --exclude=[package name]

dnf5

To exclude multiple packages, we write:

$ sudo dnf -x [package name 1] -x [package name 2] update

While dnf update updates currently installed packages to newer versions. dnf upgrade in addition to updating currently installed packages, it also removes obsolete packages.

3. Upgrading packages.

We have found that there are updates to be made, now to upgrade. We write:

$ sudo dnf upgrade

dnf7

The above command upgrades everything, however, we may not have time or the bandwidth to upgrade everything so we can opt to only upgrade a single package. For this we write:

sudo dnf upgrade [package name]

Some situations need us to downgrade a package. With dnf we can downgrade a package as follows:

$ sudo dnf downgrade [package name]

dnf8

4. Searching for packages.

Before downloading and installing a package we may want to search for it in a remote repository. For this we use the search option as follows;

$ sudo dnf search [package name]

dnf9

5. Package information.

To list package information using dnf we use the info option as follows:

$ sudo dnf info [package name]

dnf10

6. Installing packages.

We have already found our package. To install we use the install option as follows:

$ sudo dnf install [package name]

dnf11

or using yum

$ sudo yum install [package name]

dnf12

7. Installed packages.

To list all installed packages we write:

$ sudo yum list installed

or

$ sudo dnf list installed

dnf13

This can also be used to search for installed packages by piping the output to the grep command as follows:

$ sudo dnf list installed | grep [package name]

8. Package groups.

A package group is a collection of packages all serving a common function.
With yum/dnf instead of installing packages one by one or listing them in a long line, we can install the whole group of packages at once.

For a summary of the group list we use the summary option as follows:

$ sudo dnf groups summary

dnf14

To list package groups by writing:

$ sudo dnf grouplist

dnf15

To get information about a single group among the listed groups we use the info option followed by the name of the group as follows:

$ sudo dnf info [group name]

dnf16

Now we know enough, to install the group we write:

$ sudo dnf group install [group name]

dnf17

9. Removing a package.

If we have no use for a package anymore, it is wise to remove it. With dnf/yum we can remove packages by writing:

$ sudo dnf remove [package name]

dnf18

To remove all packages that are no longer needed, i.e, packages that were first installed as dependencies, we write:

$ sudo dnf autoremove

10. Repositories.

A repository is a remote location or URL where a Linux system fetches software and updates.

Using dnf/yum we can list available repositories by writing:

$ sudo dnf repolist all

dnf19

An available repository could not be working, to list only available repos we write:

$ sudo dnf repolist enabled

dnf20

To specify a specific repository where we want to install a package from we write:

$ sudo dnf --enablerepo=[repo name] install [package name]

dnf21

11. Package dependencies.

A package dependency is whereby one package depends on another to function. For example a Nmap package depending on the low-level networking libraries.
We can list all packages dependencies using the deplist option as follows:

$ sudo dnf deplist [package name]

dnf22

12. Package management history.

Linux systems administration involves a lot of repetitive work, for example, we have installed all required packages on one computer. Do we need to really repeat the same commands on another system? Of course not, we can create a script that does this job for us but for that, we need to remember all commands we executed.
In other cases, we may need to roll back a malfunctioning package from the system.
With dnf/yum we can list previously executed commands by using the history option as follows:

$ sudo dnf history

dnf23

We can also write:

$ sudo dnf history list

From the output, in the first column, we have the IDs of the histories. We can use this number to get additional information about a particular history:

$ sudo dnf history info [id number]

dnf24

Now if we found a history we want to undo to fix mistakes we use the undo option as follows:

$ sudo dnf history undo [id number]

dnf25

To redo a history we use the redo option:

$ sudo dnf history redo [id number]

dnf26

A rollback involves removing an update we had initially applied to an installed package.
To rollback a package we write:

$ sudo dnf history rollback [id number]

dnf27

13. Clearing cache.

By default, all package information is stored in the /var/cache/yum directory. Over time the size of this file. We can clean this up and free disk space by writing:

$ sudo dnf clean all

dnf28

14. Security fixes.

Updating packages is important to fix vulnerabilities. With dnf/yum we can decide to only install updates involving security and bug fixes.

First, we can check if there are any security updates by writing:

$ sudo dnf check-update --security

dnf29

To check for bug fixes we write:

$ sudo dnf check-update --bugfix

dnf30

To update packages we write:

$ sudo dnf update --security

dnf31

15. dnf shell.

dnf and yum come with their own shell environment where we can do all we have discussed.
To launch the shell we write:

$ sudo dnf shell

dnf32

To launch the yum shell we write:

$ sudo yum shell

dnf33

Differences between dnf and yum.

Although we can use both tools interchangeably, some differences exist which make one more preferable than the other.
dnf is a next-generation version of yum because many issues remain unresolved with yum for example performance, dependency resolution, memory usage.
dnf solves dependency resolution by using the libsolv which also improves performance.
Also, apart from yum having an undocumented API it cannot run on the latest python version.

Summary.

In this article we have seen how to manage packages in RHEl Linux distributions using dnf and yum package manages.

We have also seen the differences between the two package managers and why one is preferred over the other.

References.

  1. For the commands' manual we execute the command $ man dnf or $ man yum.
Managing packages with yum/dnf in RHEL
Share this