It’s an RPM-based package manager used in a number of Linux Distros
which include but are not limited to the likes of Fedora
, RHEL among other to install and update packages. DNF maintains CLI compatibility with Yum as its the next major version release, you will see that most of the commands will be similar to yum commands.
DNF has the capability to automatically resolve dependency issues and is similar in operation to other package managers like the familiar “apt-get” that is commonly found in Debian
The following examples can be used to demonstrate the normal usage for the DNF in the normal Linux working environment.
DNF usage command examples
1. To Install New Package From Repository
DNF command can be used in conjunction with the install keyword argument, followed by the name of the package you want to install. For instance to install Apache server we use the ‘httpd’ package keyword in the following manner.
[root@centos7 ~]# dnf install httpd
In the preceding example, one would be prompted to press the ‘y’ key to mean yes but to omit this step we can simply pass the parameter ‘-y’ as an option to denote that the yes choice should be assumed. This is done in the following manner.
[root@centos7 ~]# dnf install httpd-manual -y
This way we will not be prompted for any input and dnf will assume yes every time.
3. To Check For Available Updates
We run DNF using the ‘check-update’ argument which will check availability in our enabled repositories for any updates. However please note that this does not actually perform the update but simply gives us a list of the installable packages that are available.
[root@centos7 ~]# dnf check-update
4. To Update New Package From Repository
Earlier we had done a command that gives us a list of the available packages, to perform an update to a particular package we simply specify it after the ‘update’ argument like this –
[root@centos7 ~]# dnf update bash -y
Note that we do not have to run check-update prior to this. While we can update specified packages in this manner, it is often easier to simply apply all available updates for all packages on the system with ‘dnf update’.
5. Download Package RPM File
Rather than installing a package from the repository as demonstrated previously, we can optionally download the .rpm file from the repository with the DNF download plugin. This is an example of what happens if you attempt to perform an action without the appropriate plugin.
[root@centos7 ~]# dnf download httpd
This plugin is part of the dnf-plugins-core which we must first install.
[root@centos7 ~]# dnf install dnf-plugins-core
Now we can download the RPM file to the local system.
[root@centos7 ~]# dnf download httpd
[root@centos7 ~]# ls -la httpd-2.4.6-45.el7.centos.x86_64.rpm
6. Perform Local Install Of RPM File
In this example, we will install .rpm file that we just downloaded with the dnf download the plugin. While we could have just installed this package from the repository directly with ‘dnf install’. Sometimes you may be provided with .rpm files directly for installation so it’s worth knowing how to install them.While .rpm files can be installed with the ‘rpm’ command, using dnf has the advantage of automatically detecting and installing any other package dependencies that may also be required.
[root@centos7 ~]# dnf install unbound-1.4.20-28.el7.x86_64.rpm
We can see that the source of the unbound package is listed as the command line, as we have the file locally to install. The other packages that are installed as dependencies are listed as coming from the base repository though.
7. To Uninstall A Package
Packages can be uninstalled with the ‘remove’ argument as shown below.
[root@centos7 ~]# dnf remove httpd
Note that in order to remove a package, all other packages which depend on it will also be removed. For that reason, it is recommended not to use the -y option to ‘assume yes’ when removing a package so that you get a chance to read what will be removed before proceeding as it may be more than you expect.In the above example, the httpd-manual package that we installed previously requires the httpd package. Therefore when we remove the httpd package, httpd-manual must go too.
8. To Reinstall A Package
If you’re having a problem with a package, you can easily reinstall it with the ‘reinstall’ argument.
[root@centos7 ~]# dnf reinstall httpd -y
This is similar to performing a ‘dnf remove’ followed by a ‘dnf install’, however here it’s done in the one command and custom configuration is not removed, as a ‘dnf remove’ will delete all configuration files managed by the package.
9. View Repository Information
By default, we have many repositories configured in the /etc/yum.repos.d/ directory which dnf reads, these can be viewed with the ‘repolist’ and ‘repoinfo’ arguments.
[root@centos7 ~]# dnf repolist
By default ‘repolist’ displays information for enabled repositories only, however, we can specify ‘all’ afterward to list even disabled repositories.
[root@centos7 ~]# dnf repolist all
We can specify a new repository by manually editing or creating a new .repo file in the /etc/yum.repos.d directory, however, we can much more easily create a persistent repository with the ‘dnf config-manager’ command.
[root@centos7 ~]# dnf config-manager
[root@centos7 ~]# cat /etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo
We simply provide a known repository URL in the –add-repo option and this creates a .repo file based on the name of the repository URL specified. In this case, etc/yum.repos.d/mirror.aarnet.edu.au_pub_centos_7.repo has been created with the contents specified above in the output of the command. We can now install or update packages from this newly specified mirror.There are many more commands that can be done using DNF, we shall create another article detailing more command examples that can be used with DNF if deemed necessary but in the mean time please feel free to experiment with the commands listed in the inbuilt help.