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
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. The example gave the less command to list packages full screen at a time.
dnf list available | less
Use the F key to move forward and the B key to move backward. 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. To install the Firefox browser, for example, 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 will manage the installation of all dependencies for a package. To see all dependencies set up as part of a Firefox installation, use the deplist subcommand 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 remove command.
sudo dnf remove firefox
Another way to remove packages is through the historby subcommand. 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
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 the history sub-command, you can undo or delete any previous transaction. 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 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 a remote repository, you can use the check-update subcommand as follows:
sudo dnf check-update
After fetching the updates, you can apply them to all installed software packages using update.
sudo dnf update
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.
You should read it
- The best Linux distributions for Raspberry Pi
- What is the difference between Linux distributions?
- 7 best Linux distributions based on Red Hat
- 5 distributions based on the best Arch Linux
- 5 best Ubuntu-based Linux distributions of all time
- Instructions for using dpkg command on Linux Debian
- 11 best Linux distributions for programmers
- Top 8 most beautiful Linux distributions in 2022
- 9 most popular Linux package managers today
- 9 best Debian-based Linux distributions
- 3 main types of Linux distributions that you should know
- How to Create Your Own Linux Distribution Using Yocto