DNF (Dandified Yum) is an RPM-based package manager capable of managing packages in Linux. Today, we'll go through 20 DNF command examples. These examples will teach you how to manage packages with ease.
You can use DNF to install and update packages. It is a popular package manager and comes pre-installed as the default package manager in RHEL 8, Fedora 22, and CentOS.
Before moving forward, let's look at the definition of package manager.
What is a package manager in Linux?
A package manager is a collection of tools that helps automate package management, including searching, downloading, installing, upgrading, and removing packages within an operating system.
If you are an ubuntu user like me, you are probably familiar with tools like apt, aptitude, apt-get and dpkg that are used to manage .deb based package.
A package manager can be a command line tool or a graphical user interface app. Currently, there are many popular package managers available for Linux. These include:
- APT (Advanced Package Tool)
- rpm (RedHat Package Manager)
- yum (Yellowdog Update Modified)
- dnf (Dandified Yum)
- dkpg (Debian Package Manager)
To truly understand package managers, we must also learn about "package."
A package is a compressed software archive file that offers functionality, either standalone or part of a software application. It can be a GUI application, command line utility, or software library. In addition, you can find software dependency files, binary executables, and configuration files inside a package.
Depending on the package manager, the package extension can be .deb, .rpm, .tgz, etc.
These package managers also use package sources known as repositories to download new packages.
In short, a package manager takes care of the following:
- Extracting package archives
- Making sure that the package is authentic by checking the digital certificates
- Checking for package integrity by authenticating checksums
- Taking care of essential package management
What is DNF package manager?
DNF package manager is a Fedora-based package manager. It is a successor to YUM. At its core, DNF takes care of dependency checking. It performs faster and requires fewer inputs from the user. By doing so, the user doesn't have to manually review or update package dependencies.
Under the hood, DNF uses the rpm command. When originally released, DNF used Python. However, the team has recently been trying to move it to C. Also, it uses gpg signature verification to ensure package integrity and verifiability.
DNF vs. YUM
DNF is the successor to YUM. It improves on YUM in every criterion, including performance, compatibility, and performance.
YUM suffers from slow performance as it lacks proper memory synchronization to repository metadata. DNF solves this by ensuring adequate synchronization. Moreover, if you're a developer, you wouldn't find YUM developer-friendly as it doesn't offer good API documentation. On the other hand, DNF ensures proper API documentation by adhering to strict API rules.
As for dependency solving, DNF uses 'libsolv.' It is an advanced dependency solver that is fast and accurate. YUM lacks this feature and depends on public API for dependency resolution.
Lastly, DNF lets users delete Kernel packages if needed. YUM lacks this feature.
20 DNF command examples to manage packages
In this section, we'll look at 20 DNF command examples. These examples will help you learn how to use the DNF command effectively.
To follow the guide, you must have access to a Linux distribution that uses the DNF package manager. For example, you can use CentOS, Fedora, RHEL, or even Oracle Linux. However, if your distro doesn't come pre-installed with DNF, then you need to use the following command to install it.
$ yum install dnf
1. Checking DNF version
To check the DNF version installed on your system, run the command:
$ dnf --version
It'll output the version as below.
4.14.0 Installed: dnf-0:4.14.0-1.fc37.noarch at Sun Dec 11 05:49:07 2022 Built : Fedora Project at Fri Sep 9 13:05:18 2022 Installed: rpm-0:4.18.0-1.fc37.x86_64 at Sun Dec 11 05:49:07 2022 Built : Fedora Project at Wed Sep 21 10:51:10 2022
2. List the installed packages
To list installed packages on your system, run the following command:
$ dnf list installed
Installed Packages ModemManager-glib.x86_64 1.18.12-1.fc37 @updates NetworkManager.x86_64 1:1.40.10-1.fc37 @updates NetworkManager-libnm.x86_64 1:1.40.10-1.fc37 @updates alternatives.x86_64 1.21-1.fc37 @koji-override-1 audit.x86_64 3.0.9-1.fc37 @fedora audit-libs.x86_64 3.0.9-1.fc37 @anaconda authselect.x86_64 1.4.2-1.fc37 @koji-override-1 authselect-libs.x86_64 1.4.2-1.fc37 @koji-override-1 basesystem.noarch 11-14.fc37 @anaconda bash.x86_64 5.2.15-1.fc37 @updates
As the list is long, you can pipe the output to more or less. This will show limited packages on your screen.
$ dnf list | more
$ dnf list | less
If you want to search for a specific installed package, then you need to add its name at the end of the command.
$ dnf list installed [package-name] [term] For example, if you want to learn whether or not the <strong>zlub.x86_64 package</strong> is available on your system, run the following command. [term] dnf list installed zlub.x86_64
3. List the available packages
Similarly, you can also check the available packages. To do so, run the following command:
$ dnf list available
It'll look for the fastest mirror and see if the package is available.
[[email protected] ~]$ dnf list available zip Last metadata expiration check: 0:10:46 ago on Wed Mar 1 19:04:36 2023. Available Packages zip.x86_64 3.0-33.fc37 fedora
If there is nothing to show, it'll show an error: No matching Packages to list
4. Install a specific package using DNF
To install a package using DNF, you need to use the install argument and specify the package name. The syntax of the command is as below.
For example, if you want to install Python, then the command is:
$ sudo dnf install python
Note: The package installer will ask you for confirmation when installing packages. Press Y to continue and N to cancel.
If you want to install from a specific package, use the --enablerepo argument.
$ dnf --enablerepo=epl install httpd
5. Check for new package updates from the repository
You can update new packages from the repository with the check-update argument. With this argument, the DNF command looks for updates for installed packages. However, it only shows the available updates and does not carry out any updates.
$ dnf check-update
6. Update the new package from the repository
You need to use the update argument to update the new packages. If you follow it with the package name, it'll only update that specifically. Otherwise, it'll update all existing packages that have updates available.
$ dnf update bash -y
For updating a specific package, the syntax reads as:
$ dnf update package-name
For example, if you want to update the audit.x86_64 package, you need to enter the following command in the terminal.
$ dnf update audit.x86_64
Note: To make it work, you need to first run the check-update argument.
7. Get specific information about the package
Many times, you're not sure whether or not to update the package. To help you, the DNF command offers the info argument that outputs package details in the terminal.
The syntax is as below
$ dnf info package-name
For example, if you want to get info about the httpd package, you can do it by copy-pasting the following command in the terminal.
$ dnf info httpd
Last metadata expiration check: 2:23:56 ago on Wed Mar 1 19:04:36 2023. Available Packages Name : httpd Version : 2.4.55 Release : 1.fc37 Architecture : i686 Size : 52 k Source : httpd-2.4.55-1.fc37.src.rpm Repository : updates Summary : Apache HTTP Server URL : https://httpd.apache.org/ License : ASL 2.0 Description : The Apache HTTP Server is a powerful, efficient, and extensible : web server. Name : httpd Version : 2.4.55 Release : 1.fc37 Architecture : x86_64 Size : 51 k Source : httpd-2.4.55-1.fc37.src.rpm Repository : updates Summary : Apache HTTP Server URL : https://httpd.apache.org/ License : ASL 2.0 Description : The Apache HTTP Server is a powerful, efficient, and extensible : web server.
8. Check the package contents
You can further learn about the package by learning about its contents. The DNF command offers the provides argument to check the details quickly.
$ dnf provides package-name
For instance, if you want to check Python package content, you need to run the following:
dnf provides Python
Last metadata expiration check: 2:27:59 ago on Wed Mar 1 19:04:36 2023. python-unversioned-command-3.11.0-1.fc37.noarch : The "python" command that runs Python 3 Repo : fedora Matched from: Provide : python = 3.11.0-1.fc37 python-unversioned-command-3.11.2-1.fc37.noarch : The "python" command that runs Python 3 Repo : @System Matched from: Provide : python = 3.11.2-1.fc37 python-unversioned-command-3.11.2-1.fc37.noarch : The "python" command that runs Python 3 Repo : updates Matched from: Provide : python = 3.11.2-1.fc37
9. Search the package and its related details
The info argument shows package details. However, what happens when you want to search for a package? In that case, the DNF command offers the search argument. It'll return two sections - the first where it lists if it matches the given name, and the second where it provides a summary/description.
$ dnf search package-name
$ dnf search httpd
10. Downloading RPM file package
You can also use the DNF command to download RPM files. To do so, you need to use the download argument, followed by the package name.
$ dnf download package-name
However, to use it, you need to install dnf-plugins-core package.
$ sudo dnf install dnf-plugins-core
Once done, run the DNF download command to download its RPM file.
$ sudo dnf download httpd
[[email protected] ~]$ sudo dnf download httpd [sudo] password for nitt: Last metadata expiration check: 1:23:19 ago on Wed Mar 1 20:52:01 2023. (1/2): httpd-2.4.55-1.fc37.x86_64.rpm 392 kB/s | 51 kB 00:00 (2/2): httpd-2.4.55-1.fc37.i686.rpm 40 kB/s | 52 kB 00:01
11. Installing manually downloaded package
Now, with a manually downloaded .rpm package, we can install it manually with the localinstall argument. It resolves dependencies automatically.
$ dnf localinstall package-name.rpm
Note: This method works with .rpm files only.
For example, we'll try to install the httpd.rpm package that we downloaded in the previous step.
To do so, the command needs to be:
$ dnf localinstall httpd-2.4.55-1.fc37.x86_64.rpm
Press Y to continue the installation.
If you don't want to type or copy-paste the long package name, then you can also install it with the following command.
$ dnf install *.rpm
Note: This command will install all .rpm packages within the working directory. So, if you want to install a specific .rpm, then mention its name. Otherwise, you can keep only the required .rpm files in the directory.
12. Reinstall a package
If you find any packaging issue and want to reinstall it, you can do it by using the reinstall argument.
$ dnf reinstall package-name
Let's reinstall the httpd package we installed manually.
$ dnf reinstall httpd
13. Uninstall a package
To uninstall a package, you need to use the remove argument. The syntax for it is as below.
$ dnf remove package-name
Note: You can also use it to uninstall an application.
14. Downgrading a package
If you want to downgrade a package, you can install the downgrade argument, followed by the package name you want to downgrade.
$ dnf downgrade package-name
Let's downgrade the Python package.
$ dnf downgrade python
15. Upgrading a package
Like downgrading, you can also upgrade a package with the upgrade argument, followed by the package name.
$ dnf upgrade package-name
Let's upgrade the Python package that we downgraded earlier.
$ dnf upgrade python
16. Upgrading or downgrading all packages
You must use the distro-sync command to upgrade or downgrade all packages based on the system's latest version.
$ dnf distro-sync
17. Update the system with DNF
You can use the DNF command to check system-wide updates. This is common for different RPM-based distros.
To check and list updates for your system, run the following command.
$ dnf check-update $ dnf list updates
And, if you want to install all updates at once, run the dnf update command.
$ dnf update
Moreover, you can update specific packages by using the following command.
$ dnf update package-name
18. Build and Clear Cache Information
DNF uses a cache for faster execution. It stores the cache in the /var/cache/dnf directory. Here, it keeps all repository and package information.
If the DNF command is not working as intended, you can troubleshoot it by clearing the cache. This solves problems with incorrect data.
$ dnf clean all
You can also remake the cache by using the makecache argument.
$ time dnf makecache
Note: Cache builds over time, irrespective if you run makecache or not.
19. Install security updates
The DNF command lets you perform security updates only to your installed packages. This can help you secure your working environment or a production environment.
To install security updates to your packages only, you need to use the following command:
$ dnf updateinfo list sec
20. Display verbose information
By default, the DNF command doesn't display detailed information. However, it can hide vital information required for troubleshooting. You need to add -v argument to the command to make it output detailed information.
For example, if you want to install httpd and want additional information, you need to run the command:
$ dnf install httpd -y -v
The DNF package manager is a powerful package management solution for modern and powerful Linux operating systems such as Fedora, CentOS, and RHEL. It gives the user power while automating the most important aspects behind the scenes.
That's it! We've covered 20 necessary DNF commands that you should know. Congrats on becoming a DNF Pro.