Dnf is the default high-level package manager in the Red Hat family of distributions, which includes Fedora, Red Hat Enterprise Linux and all its clones. It is the successor of Yum, and indeed using the yum command in recent versions of the distributions mentioned above, is just another way to call dnf. Dnf has a lot of nice features and plugins which help us install, update and remove software packaged in the “.rpm” format. In this tutorial we explore dnf package groups and learn how to handle them.

In this tutorial you will learn:

  • What is a package group
  • How to get information about a package group
  • How to list all available package groups
  • How to install, upgrade and remove a package group
How to work with dnf package groups
How to work with dnf package groups

Software requirements and conventions used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Distributions which uses dnf as package manager
Software dnf
Other None
Conventions # - requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux-commands to be executed as a regular non-privileged user

What is a package group?

Let’s start by defining what a package group is. A package group is basically a “virtual” package. Here we call it “virtual” because it doesn’t provide a specific software per-se, but it references other “real” packages. We can use package groups to install a “set” of packages with a single command. Say for example we need to install the packages needed to work with kvm virtual machines on Fedora: instead of installing each package singularly, we can just install the “virtualization” package group, which will cause all the needed software to be installed on our system.

Getting information about a package group

Before we install a package group, we may want to see what packages will be pulled in by it. To accomplish this task, all we have to do is to use the dnf group info command, passing the name of the package group we want to inspect as its argument. To see what the @virtualization package groups contain, for example, we would run:

$ dnf group info virtualization

SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Here is the output of the command above on a Fedora 34 system:

Group: Virtualization
 Description: These packages provide a graphical virtualization environment.
 Mandatory Packages:
   virt-install
 Default Packages:
   libvirt-daemon-config-network
   libvirt-daemon-kvm
   qemu-kvm
   virt-manager
   virt-viewer
 Optional Packages:
   libguestfs-tools
   python3-libguestfs
   virt-top

We can increase the verbosity of the command, and receive more detailed information by invoking it with the -v (short for --verbose) option:

Group: Virtualization
 Group-Id: virtualization
 Description: These packages provide a graphical virtualization environment.
 Mandatory Packages:
   virt-install-3.2.0-3.fc34.noarch                                                                 @System
 Default Packages:
   libvirt-daemon-config-network-7.0.0-4.fc34.x86_64                                                @System
   libvirt-daemon-kvm-7.0.0-4.fc34.x86_64                                                           @System
   qemu-kvm-2:5.2.0-7.fc34.x86_64                                                                   @System
   virt-manager-3.2.0-3.fc34.noarch                                                                 @System
   virt-viewer-9.0-3.fc34.x86_64                                                                    @System
 Optional Packages:
   libguestfs-tools
   python3-libguestfs-1:1.45.4-1.fc34.x86_64                                                        updates
   virt-top-1.0.9-17.fc34.x86_64                                                                    fedora

The first thing we can notice in the output are the name and the id of the package group, in this case “Virtualization” and “virtualization”, respectively. After them, we can read a brief description of the package group and its purpose, and finally the actual list of the packages included in it. We can see the packages are divided in three main sections:

  • Mandatory
  • Default
  • Optional

The packages marked as “Mandatory” and “Default” will always be installed, while the ones marked as “Optional” will be installed only if specified. For the sake of completeness we should mention that another section exists, which is not used in this case: Conditional. The packages that are part of the “Conditional” section are installed only if the packages they require are already installed.



In certain cases some packages that are part of a package group can be already present in the system. When we run the group info command with the -v option, as we did above, the packages that are part of the group and are not already installed will easily distinguishable, since they will be highlighted in the list. Here is the output of the dnf -v group info virtualization command after the virt-viewer package was installed singularly:

dnf -v group info virtualization
dnf -v group info virtualization command output

List all available package groups

To list all the available package groups in the repositories of our distribution all we have to do is to run the following command:

$ dnf group list

The command above returns the list of all the known groups. We can, however add a series of options to modify its behavior. By default, the so called hidden groups are not included in the list. To make them show up all we need to do is to add the --hidden option:

$ dnf group list --hidden

If we only want to obtain the list of all installed package groups, instead, we can use the --installed option:

$ dnf group list --installed

Installing, upgrading and removing a package group

So, how can we install a package group? There are two main ways: we can specify the name of the package prefixed with the @ symbol, or use the dnf group install command, as we already saw. The commands below are equivalent:

$ sudo dnf install @virtualization
$ sudo dnf group install virtualization

As we already said, only “Mandatory” and “Default” packages are installed by default. This default behavior, however, can be modified by using the group_package_types dnf option, either from command line or in the dnf configuration file. Let’s make an example. Suppose we want to install only the packages that are part of the “Mandatory” section of a package group, we could run the following command:

$ sudo dnf --setopt=group_package_types="mandatory" group install Virtualization


If we don’t want to specify the option each time we run a command, we can set it permanently in the dnf configuration file, /etc/dnf/dnf.conf:

[main]
# Install only Mandatory packages from package groups
group_package_types=mandatory

If we just want packages included in the “Optional” section of a package group to be included, we could also just add the --with-optional command line flag when installing a package group:

$ sudo dnf group install --with-optional virtualization

We can also have the chance to upgrade a package group. When we do so all the packages that are part of the group will upgraded together with the package group itself: this could potentially cause new packages to be installed if they have been added to the group, or removed if they are not part of a group anymore and they have been not explicitly installed by the user. To upgrade a package group we use the group upgrade command, so, for example, to upgrade the “Virtualization” package we would run:

$ sudo dnf group upgrade virtualization

Dnf also provides a command to remove an installed package group: group remove. The command will remove all packages that are part of a group from the operating system, except for those which are part of another package group, or those explicitly installed by the user. To remove the “Virtualization” package group, we would run:

$ sudo dnf group remove virtualization

Conclusions

In this tutorial we learned about package groups. We saw how to get information about a specific package group in the distributions which uses dnf as package manager, such as Fedora and Rhel, how packages which are member of a package groups are divided into sections, which of them are installed by default, and how we can modify this behavior. Finally, we learned how to install, upgrade and remove a package group.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.