One of the most attractive features of the Linux operating system is how easy it is to install or automate the installation of software packages from secure remote repositories.

This guide will walk you through how to install and manage software packages on RPM-based Linux distros such as Fedora and Red Hat Enterprise Linux (RHEL) using DNF, the next-generation package manager for RPM-based Linux distros.

What Is DNF?

DNF is the successor program of YUM (Yellowdog Updater Modified) and is the default package manager on Fedora and RHEL. The name DNF is short for Dandified YUM.

The main purpose of DNF is to ease the installation, querying, and management of software packages on both servers and desktops. Also, just like other mainstream package managers on Linux, DNF resolves all software package dependencies during the installation.

DNF also maintains backward compatibility with YUM so that your older scripts will run just fine. In fact, when you run the yum command on new Linux distros, it is actually using DNF in the background. You can verify this by running the command:

        ls -l /usr/bin/yum
    

As you can notice in the output, the yum command is simply a symbolic link to dnf.

Searching for Software Packages Using DNF

An important part of managing packages is being able to query or search for packages you are interested in, both locally and on remote repositories. You can search for packages based on the package name, package content or keywords, etc.

For example, if you want to search for some of the web browsers that you can potentially install then you could start with a general search using the keyword "browser."

        dnf search browser
    
dnf command search output for web browsers

The output is a list of all software packages that contain the word "browser" in the package name or the description.

If you want to get more info about a certain package, for example, the Firefox browser, you can use the info subcommand as follows:

        dnf info firefox
    

The output gives you more detailed information about the package, such as the architecture, package size, version number, license, etc.

You can also list all the packages available to install from the configured repositories using the list method. We've piped the less command to list the packages one screen-full at a time.

        dnf list available | less
    

Use the F key to scroll forward and the B key to scroll backward. You can also search the output for a keyword by pressing / then entering your keyword. Press Q to exit the command output.

Use the following command to view all installed software packages on your PC:

        dnf list installed
    

Installing Software Packages

Installing packages with DNF is pretty straightforward. However, you need elevated privileges as the root or sudo user. For example, to install the Firefox browser, simply run the following command then press Y in the prompt that appears to agree to the terms:

        sudo dnf install firefox
    

As mentioned earlier, the dnf command takes care of installing all dependencies for a package. To view all the dependencies installed as part of the Firefox installation, use the deplist subcommand followed by the package name.

        dnf deplist firefox
    

Uninstalling Software Packages

Removing packages is an equally important exercise when managing software. One of the easiest ways to remove or uninstall a package is by using the remove method.

        sudo dnf remove firefox
    

Another way to remove software packages is via the history subcommand. DNF keeps a record of all transactions that involve installing or removing software packages. To view previous DNF transactions, you can run the following command:

        dnf history
    
dnf command history output

The output lists previous actions or transactions in tabular form. In this case, the output shows that we've previously installed vim and chromium.

With the history subcommand, you can undo or remove any previous transactions. For example, to remove the vim package, simply run the history command with the undo option followed by the transaction ID, then press Y when prompted to proceed.

        sudo dnf history undo 3
    

As a good practice, you should get more details about a transaction before you undo it to avoid side effects. You can view the details of a transaction using the following command:

        sudo dnf history info 3
    

Remember to replace 3 with the appropriate transaction ID that you are interested in.

Related: The Best Desktop Alternatives for Fedora

Removing Unused Dependencies

One of the things that take up disk space on Linux PCs is packages and dependencies no longer needed by the system.

To remove such dependencies, run the following command:

        sudo dnf autoremove
    

In addition, DNF also allows you to remove data downloaded along with installed packages.

        sudo dnf clean packages
    

You can also clean up your software package cache and other metadata that are part of the installed packages by running the following command:

        sudo dnf clean metadata
    

Reinstalling Software Packages

Once in a while, you might have to install only specific components of a package. For example, if you accidentally delete certain software packages of firefox, you can reinstall them by running:

        sudo dnf reinstall firefox
    

Updating Packages With DNF

Updating your software is one of the best ways of maintaining a robust and secure system because new software contains the latest security patches and bug fixes.

To fetch the latest software package updates from remote repositories, you can use the check-update subcommand as below:

        sudo dnf check-update
    

Once you fetch the updates, you can apply them to all installed software packages using update.

        sudo dnf update
    
dnf update command ouput

The output shows the total number of packages DNF will update.

You can also update a specific package, for example, firefox, using the following command:

        sudo dnf update firefox
    

Learn More: Why You Should Update Packages Before Installing Software on Linux

Alternative and Modern Package Management

This guide has looked at how to manage software packages on RPM-based Linux distros such as Fedora and Red Hat Enterprise Linux (RHEL) using the DNF command. You can also use YUM and RPM package managers on Fedora.

Another modern way of distributing software packages on Linux is via Flatpak, a solution that allows you to create and distribute a package on multiple supported Linux distros.