How to manage packages on RPM-based Linux distributions with DNF


One of the most appealing 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 tutorial will show you how to install and manage software packages on RPM-based Linux distributions like Fedora and Red Hat Enterprise Linux (RHEL) using DNF.

Search for software packages using DNF

An important part of managing packages is being able to query or search for packages that interest you, both locally and across remote repositories. You can search for packages by package name, package content or keyword, etc..

For example, if you want to search for several web browsers to install, you can start with a general search with the keyword “browser”.

dnf search browser
The output is a list of all software packages that contain the word “browser” in the package name or description

If you want to know more information about a certain package, such as 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 architecture, package size, version number, license, etc..

You can also list all packages available to install from the repositories configured with the list command. Example given command less to list packages in full screen at a time.

dnf list available | less

Using the key F to move forward and key REMOVE to move backwards. You can also search the output for a keyword by pressing / then entering the keyword. Press Q to exit the command output.

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

dnf list installed

Install the software package

Installing packages with DNF is pretty straightforward. However, you need to have elevated privileges as the root or sudo user. For example, to install Firefox browser, just 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 will manage the installation of all dependencies for a package. To see all dependencies set up as part of a Firefox installation, use the subcommand deplist followed by the package name.

dnf deplist firefox

Uninstall software package

Package removal is an equally important operation when managing software. One of the easiest ways to remove or uninstall a package is to use the command remove.

sudo dnf remove firefox

Another way to remove software packages is through the subcommand historby. DNF keeps a profile of all transactions related to the installation or removal of software packages. To view previous DNF transactions, you can run the following command:

dnf history
Previous DNF transactions
Previous DNF transactions

The output lists previous actions or transactions in tabular form. In this case, the result shows that the example system previously installed vim and chromium.

With sub-command history, you can undo or delete any previous transaction. For example, to delete the package vim, just run the command history with the undo option, followed by the transaction ID, then press Y when prompted to continue.

sudo dnf history undo 3

It’s a good practice to know more details about the transaction before undoing it to avoid creating problems. You can view the details of a transaction with the following command:

sudo dnf history info 3

Remember to replace the number 3 with the appropriate transaction ID of your interest.

Remove unused dependencies

One of the things that takes up disk space on a Linux PC is packages and dependencies that the system no longer needs.

To remove such dependencies, run the following command:

sudo dnf autoremove

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

sudo dnf clean packages

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

sudo dnf clean metadata

Reinstall software packages

Sometimes, you may only have to install specific components of a package. For example, if you accidentally deleted certain firefox software packages, you could reinstall them by running:

sudo dnf reinstall firefox

Update packages with DNF

Updating software is one of the best ways to maintain a strong and secure system, as new software contains the latest security patches and bug fixes.

To fetch the latest software package updates from the remote repository you can use the subcommand check-update as follows:

sudo dnf check-update

After fetching the updates, you can apply them to all installed software packages using update.

sudo dnf update
Apply updates to all software packages
Apply updates to all software packages

The results show the total number of DNF packets to update.

You can also update a specific package, such as firefox, by using the following command:

sudo dnf update firefox

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

Another modern way to distribute software packages on Linux is through Flatpak, a solution that allows you to create and distribute a package across many supported Linux distributions.

.

Related Posts

Leave a Reply

Your email address will not be published.