FUNDAMENTALS A Complete Guide for Beginners
DNF is the successor of YUM which refers to Dandified YUM and it is the next generation of YUM. This package manager is used in RPM-based Linux distribution. As it is the modern version of Yum, it shows better performance and resolution. In this article, I will discuss the dnf package manager in detail.
What is DNF Package Manager in Linux?
Dnf is the package manager that handles packages and helps the user to efficiently manage the Red Hat-based distributions. As it builds on top of Yum it provides many additional functions and facilities. The package manager uses the dnf tool that makes the installation, removal, and upgrade of the packages easier.
The Key Components of DNF
The users who use the package manager for the first time should know about the key components of dnf. Here I have shown the modules:
- Usage: Used in modern Red Hat-based distributions, default package management tool.
- File extension: The file extension for the dnf package manager is .rpm.
- Key Features: Faster performance, Parallel downloading, rich command line interface, Enhanced dependency resolution.
- Dependency handling: Third-party dependency solver, dnf calculates and resolves dependencies and conflict resolution.
Why Use the DNF Package Manager?
Some key features make DNF the most usable package manager. Below I will show some of them:
- Use less memory while synchronizing metadata.
- Use fully documented API.
- It has a modular design.
- Efficient network.
- Improved dependency solver algorithm.
- More integrated plugins with core.
- Automatic bug reporting.
Package Management With “dnf”
Managing packages means installing, removing, searching, handling a repository, and showing information about a package. Below I will illustrate the management of packages with dnf.
Downloading an RPM Package in Linux
If you want to download an RPM package file without installing it then you can copy the following command:
sudo dnf download google-chrome-stable
- sudo: Permits administrative privileges.
- dnf: Package management system in Red Hat that provides a high-level front-end command interface.
- download: Command to download the following package.
- google-chrome-stable: Package that I want to download.
I have chosen the Google Chrome-stable, you can choose any package according to your liking.
From the above image, you can see the package which I have downloaded.
Searching a Package With “dnf”
When one needs to search a package in the repository he can locate the package with the search command. You can copy the following command on Redhat to search for a package:
sudo dnf search totem
- search: Locate a package in the repository.
- totem: The package that I searched for.
You can see all the packages whose names exactly match with totem.
Displaying Package Information
Sometimes you need to view the package information which you can see with the info option. With these options, the user can know the architecture, version, repository, and license. And also know about the package from the package description. To show the package information, copy the following command in Redhat :
sudo dnf info totem
- info: Show the information of a package.
- totem: The package whose information I want.
Installing Packages With “dnf”
The common function of any package manager is to install a package. Dnf shows variety in installation. With dnf, you can install single packages, multiple packages, and packages with binary names. Here you can see some of the installation commands below.
A. How to Install a Single Package
Firstly you can install a single package. To install a single dnf package you have to use the install option. Here I have used the httpd package You can use any package according to your liking. To practice, you can copy this command:
sudo dnf install httpd
- dnf: Package management system in Red Hat that provides a high-level front-end command interface.
- install: Command install the following package.
- httpd: The package that I want to install.
To confirm the installation you have to type Y and then press ENTER.
So, the installation has been completed with dnf. If you want to skip the confirmation section you can use the -y option in the command which means yes to all the installations.
B. How to Install Multiple Packages
The user can install multiple packages using dnf. You can copy the following command in RedHat.
sudo dnf install samba totem nginx
- samba, totem, nginx: the packages I want to install.
Here I have installed the packages that I needed. You can choose according to your preference.
C. How to Install a Specific Version of a Package
If you want to install a specific version, you can do this with dnf. To do this you can copy this command:
sudo dnf install samba-4.17.5-103.el9_2
- samba-4.17.5-103.el9_2: The specific version of a package that I want to install.
Here I installed this version of this package You can install packages according to your liking.
D. How to Install RPM Packages
Sometimes users need to install a file that has already been downloaded. So to install a file locally with dnf you can use the following command:
sudo dnf install /home/oishi/Downloads/google-chrome-stable-116.0.5845.179-1.x86_64.rpm
- /home/oishi/Downloads/google-chrome-stable-116.0.5845.179-1.x86_64.rpm: The path where the downloaded file is located.
To install a RPM file locally one must use the complete path where the file is located.
E. Installing a Package By its Binary Filename
You can install a package with its binary name. You can copy this command on RedHat:
sudo dnf install /usr/sbin/lvm
- /usr/sbin/lvm: The binary name of the package.
Finding Which Package Owns a File
If you want to see what packages a file owns then you can use the provided option. Here you can use the command that is shown below:
sudo dnf provides named
- provides: Displays which packages a file owns.
Replace the named that has been shown in the image with the full pathname like below:
sudo dnf provides /path/to/file
Remove Packages
Sometimes you install a package but later you do not need the file anymore. So you can uninstall or remove it with the remove option. In this section, I have shown how to remove a single package and unnecessary packages.
1. Remove a Single Package
To remove a single package with RedHat you can copy the following command:
sudo dnf remove samba
- remove: Remove the desired package from the repository.
- samba: The package that I want to remove.
To confirm the removal you have to press Y and then ENTER.
So, with the remove option, I have uninstalled the package. After the uninstallation process complete text has been displayed in the terminal.
Like installation, you can remove multiple packages with dnf. To uninstall multiple packages you can copy the following command:
sudo dnf remove totem samba httpd
2. Remove All Unnecessary Packages
There are many unnecessary packages installed in the system as dependencies which creates potential issues and also uses disk space. To uninstall any dependency packages that are not required by any installed packages, in Red Hat, you can copy this command:
sudo dnf autoremove
- autoremove: Uninstall any dependency that is not required by any installed packages.
From the image, you can see I have removed all the unused or unrequired dependencies with the command.
Reinstall Package
When you want to install the failed packages that have been not installed you can reinstall the package with the following command:
sudo dnf reinstall samba
- reinstall: Reinstall the failed packages.
- samba: The package that I want to reinstall.
If you reinstall an already installed package then it will reinstall the newer available version.
Show List of Packages With “dnf”
Sometimes users need to know the list of packages, the list of installed packages and whether a specific package has been installed or not. So I will show this list of packages with dnf command below:
A. How to Show the List of All Packages
If you want to see the list of all packages that are available in the system you can copy the following command:
sudo dnf list
- list: Shows all the packages in the system.
With this command, you will see a huge list of packages as it shows all the installed, available installation packages on the system.
B. View List of All Installed Packages Using “dnf”
If you want to see the RPM packages that you have installed locally then copy the following command on RedHat:
sudo dnf list installed
- list installed: List of installed packages.
From the image, you can see the rpm packages installed locally.
C. Check a Specific Package Whether It is Installed or Not
When you need to see if a specific package is installed or not then you can copy the following command:
sudo dnf list installed | grep totem
Update and Upgrade Packages
One important function of a package manager is to update the packages. With dnf, you can update the full system and also single and multiple packages. Here below I have shown how to use the update command:
1. How to Check an Update
Firstly if you want to see the packages that you need to update then check the update list with the check option. It will show the list of available packages from the enabled repository. To see the list you can copy the following command:
sudo dnf check-update
- check-update: Shows the list of upgradable packages.
2. Update All Packages Using “dnf”
When you want to update all the packages you can copy this command in Redhat:
sudo dnf update
- update: Command to make packages up to date.
Here I update all the available packages with the latest version. From the image, you can see with dnf, the upgrade is also done with the update command.
From the image you can see, to confirm the download of the upgraded version, you have to press the Y button. Then you have to press ENTER.
3. Update a Specific Package
When you want to update a single or multiple packages you can copy the following command with dnf in RedHat:
sudo dnf update totem httpd
- totem, httpd: The packages that I want to update.
System Upgrades With DNF System Plugin
To upgrade your RHEL system with dnf you can do this with the system upgrade plugin. Firstly you have to upgrade all the packages to the latest version. It is an important part of system upgrade. So by the following command, you can upgrade the packages:
sudo dnf upgrade --refresh
- upgrade: Command to upgrade to the new version of packages.
- – -refresh: Forces to immediate upgrade.
After upgrading all the packages you must install dnf-plugin-system-upgrade if it is not available. You can copy the following command:
sudo dnf install dnf-plugin-system-upgrade
- install: Command install the following package.
- dnf-plugin-system-upgrade: A plugin to upgrade the system to the current release version.
After the installation, you can download the upgraded version to upgrade the system. Here I have shown the command:
sudo dnf system-upgrade download --releasever=38
- system-upgrade: Upgrade to a newer version to increase functionality.
- download: Command to download the following version.
- – -releasever=38: The newer version of the system.
You can choose the number of the latest version that you want to download. After the upgrade, you must reboot your system.
Language Support Using DNF
Dnf provides language support. With dnf, you can install and remove language support. Below I have shown how to install and remove language support.
A. Install Language Support
To install language support you have to use langpacks with the language name code. Here I have installed Danish language whose language code is da. To install language support you can copy the following command:
sudo dnf install langpacks-da
- langpacks: The language package.
- -da: The language support I installed (da stands for Danish).
B. Uninstall Language Support
To uninstall language support you can copy the following command on RedHat:
sudo dnf remove langpacks-da
- remove: Remove the desired package from the repository.
- langpacks: The language package.
- -da: The language support I installed (da stands for Danish).
Core Plugins of the Package Manager
If you want to increase the functionality of dnf then you can install the core plugins. Here I have used the noarch plugin. You can install the core plugin with the following command:
sudo dnf install dnf-plugins-core-4.3.0-5.el9_2.noarch
- dnf-plugins-core-4.3.0-5.el9_2.noarch: Package file name.
- dnf-plugins-core: Package name.
- 3.0: Package version.
- el9_2:Package release.
- noarch: Package architecture.
If you want to install a third-party plugin then you can use the following command syntax replacing the plugin name with your preferred one:
sudo dnf install dnf-plugins-extras-[plugin name]
Excluding Packages From Transactions
Sometimes you need to exclude any specific package from the transaction. So to exclude any package from a transaction like an upgrade you can copy the following command:
sudo dnf upgrade --exclude=kernel
- – -exclude: Remove a specific package from a function.
- kernel: The package that I exclude.
Some packages include bugs while upgrading. So it is important to remove the package from upgrading.
You can exclude multiple packages at the same time with space. To exclude multiple packages you can copy this command:
sudo dnf upgrade --exclude=kernel --exclude=httpd
- upgrade: Command to upgrade to the new version of packages.
- exclude: Remove a specific package from a function.
- kernel, httpd: The packages I want to exclude.
You can also exclude a package by changing the configuration file. It is permanently excluded until you again manually change the configuration file. You can add the packages that you want to exclude in the /etc/dnf/dnf.conf file. To open the configuration file you can copy the following command:
sudo nano /etc/dnf/dnf.conf
- nano: A common tool for creating a new file, quickly picking into a file, and editing it.
- /etc/dnf/dnf.conf: Configuration file where utilities and configuration information are stored.
After opening the file you can add the following line to the file:
exclude= httpd php mysql in /etc/dnf/dnf.conf configuration file.
I have excluded these packages you can add any packages according to your need.
After writing the name of the excluded packages you must save the edit with the write-out option and press CTRL+O and ENTER. And lastly, CTRL+X to exit from the page.
Using the DNF Versionlock
In the transaction, if you want to limit the amount of files you can use version lock. The versionlock option will lock a package version and will not be upgraded while updating the system. Firstly to lock a version you have to install the version lock command. So you can copy the following command:
sudo dnf install 'dnf-command(versionlock)'
- dnf: Package management system in Red Hat that provides a high-level front-end command interface.
- install: Command install the following package.
- versionlock: Plugin which takes names and versions and excludes the packages.
Then I used the query option to see which package version is available of the package kernel. You can this command from below:
sudo rpm -q kernel
- rpm: Red-hat package manager to install, uninstall, and manage software packages.
- -q: Query command to retrieve information using rpm command.
- kernel: The package name.
From the image, you can see there are two versions present in the system. Here I have shown which version I will lock. To lock this version you can use the following command:
sudo dnf versionlock add kernel-5.14.0-284.25.1.el9_2.x86_64
- versionlock: Command to lock a specific version.
- add: Subcommand for versionlock to which add the following package into versionlock.
- kernel: Package name.
- 14.0: Package version.
- 25.1.el9_2: Package release.
- x86_64: Package architecture.
From the image, you can see I have shown using the following command whether it is locked or not:
sudo dnf versionlock list
- list: List of locked package versions.
And you can see it shows the locked version and it is locked.
Now if you want to delete the version that you have locked before then copy the following command:
sudo dnf versionlock delete kernel-0:5.14.0-284.25.1.el9_2.*
- delete: Command to remove the locked version.
- kernel-0:5.14.0-284.25.1.el9_2.*.
After deleting the version if you want to check whether it is deleted or not then use the following command:
sudo dnf versionlock list
So no version is locked anymore.
Managing Package Groups Using “dnf”
If you can install, or remove a package group then it is easy and efficient to manage the system as with a single command you can install the whole software group. Dnf provides the feature of the software group like Server with GUI and network server. Below I have shown how to manage a software group.
1. List All Package Groups
If you want to see all the available software groups then you can copy the following command:
sudo dnf grouplist
- grouplist: Display all the available and installed group list.
You can see all the available environments, groups and install environments and groups.
2. List All Packages in a Group
If you want to see the packages in a software group you can do this with dnf. Firstly I have shown which group I want to see. For that, you have to use the following command:
sudo dnf grouplist
Here I want to see the packages inside the system tools group. So for that, I have used the following command:
sudo dnf groupinfo "System Tools"
- groupinfo: Show the information of a group of packages.
- System Tools: A group of packages.
From the image, you can see there are default and optional packages inside the System Tools group.
3. Installing a Package Group
Installing a group of packages with a single command has solved many problems if you want to install the items in the system tools group then you have to install many libraries and packages which is very difficult. But with the group option, you can install them with a single command:
sudo dnf groupinstall "SystemTools"
- groupinstall: Install the following group of packages.
- System Tools: The group of packages that I want to install.
You can see from the image all the packages have been installed with a single command.
4. Removing a Package Group
If you want to remove or uninstall a group of packages then you can copy the following command:
sudo dnf groupremove "System Tools"
- groupremove: Remove the following group of packages.
- System Tools: The group of package that I want to remove.
So, in dnf by using the group option you can install and remove a group of packages easily.
Manage Repository With “dnf”
You can handle repositories with dnf. First I want to see the repository list. To display the repository list you can copy the command:
sudo dnf repolist
- repolist: Show the current repository.
From the image, you can see the current repository list.
A. Add a Repository
Users can add a new repository by two methods:
- Adding [repository] manually.
- Adding repo file.
You need config-manager to add a repository and have to add the repository URL after the add-repo option. You can copy the following command:
sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- config-manager: Works on configuration of the repository.
- – -add-repo: Add the following url repository to the current repository.
- https://download.docker.com/linux/centos/docker-ce.repo: The Repository url which I want to add.
After adding the repository, you can see whether it is added or not by the repolist. Use the following command to see the list:
sudo dnf repolist
From the image you can see the new repository is added.
B. Enable a Repository Using “dnf”
You can see which repository is enabled and which one is not by using the following command:
sudo dnf repolist all
- repolist all: Show the current repo list with enabled and disabled repositories.
Here I will enable the repository that I marked in the image below.
If you want to enable the repository you can use the following command:
sudo dnf config-manager --set-enabled zfs
- – -set-enabled: This option will enable the following repository.
- zfs: The repository I want to enable.
After enabling the repository if you see the repolist you can see that the repo has been enabled.
C. Disable a Repository
Firstly to disable a repository, I will see the repository list. From the image, you can see I want to disable the repository that I added before.
So, to disable the repository from the directory you can copy the command:
sudo dnf config-manager --set-disable docker-ce-stable
- – -set-disable: This option will disable the following repository.
- docker-ce-stable: The repository I want to disable.
From the image, you can see to disable a repository you have to use the disable option and the repository name.
2 Examples to Install Popular Apps Using “dnf” Package Manager
You can install apps using the dnf. As you use other commands you can use them for installing apps as well. Below I have shown how to install 2 popular apps Firefox and GIMP:
1. Install Firefox Using “dnf”
To install an app Firefox you can use the following command which is similar to install packages:
sudo dnf install firefox
- install: Command install the following package.
- firefox: The app name I want to install.
You can see that, Firefox is installed, from the image.
2. Install GIMP Using “dnf”
Another app GIMP can also be installed in the same process. So use the previous command only change the app name which I changed here only. You can choose any app according to your liking.
You can see, the app GIMP is installed, from the image.
Conclusion
In this article, I have tried to describe how dnf functions, and some useful command-line tools to manage the packages efficiently. Considering how difficult to learn to use the command line for beginners I tried to keep it simple as I could. So after reading this article, you will be able to use dnf properly and manage the system.
People Also Ask
What does dnf package manager do in Linux?
As a software package manager, DNF or Dandified YUM installs, updates, or removes software packages. It is the upgraded version of YUM (Yellow-Dog Updater Modified) that makes it simple to manage software packages for Linux by automatically checking and resolving dependencies and performing actions of installation, updation, and deletion of packages.
What is the dnf command in Linux?
The Linux dnf command is a package management command for Linux distros such as RHEL, Fedora, Cent OS, etc. To install, remove, or update software packages using the dnf package manager, the command “dnf” is the primary tool. For example, to install a package using the dnf command, type the command dnf install <package_name>
.
Why use DNF instead of YUM?
You should use DNF because it provides better performance, and dependency resolution and uses less memory than yum. And Dnf has a fully documented API but Yum has no documented API.
How can I install packages using the dnf package manager?
To install a software package using the dnf package manager, open the terminal and run the command sudo dnf install <package_name>. This will install the single package package_name. In addition, you can install multiple packages by running the command sudo dnf install <package1> <package2> <package3>. For instance, the command sudo dnf install tigervnc
installs the software package TigerVNC while running the command sudo dnf install samba vlc
installs both the packages Samba and VLC media player.
Which is better DNF or APT?
Apt and Dnf are used in Debian-based distribution and RedHat-based distribution respectively. Apt and dnf are quite the same but dnf provides more unique features than apt. So you can use dnf over apt.
How to check available package updates using DNF?
To list the available software package updates using the DNF package manager, type the command dnf check-update
on the prompt and press ENTER. This will display the available updates without installing them on the system.
Does Rhel 8 use DNF?
Yes, It is the new packager manager used to manage packages on RHEL 8.
Can I display the list of repositories using dnf package manager?
Absolutely. To display the list of the system repositories using dnf, open the terminal and type the command dnf repolist
. Upon hitting the ENTER button, it displays the list of the enabled repositories of the system. In addition, running the command dnf repolist --all
returns the list of both the enabled and disabled repositories.
Related Articles
- How to Use Yum Package Manager in RHEL [A Total Guide]
- A Total Guide on RPM Package Manager in Linux
- Apt Package Manager [A Complete Guide on How to Use it]
- The Synaptic Package Manager [A Complete Guide]
- Pacman Package Manager in Linux [How to Use It]
<< Go Back to Package Manager Examples | Package Management in Linux | Learn Linux Basics