The following examples can be used to demonstrate the normal usage for the DNF in the normal Linux working environment.
1. To Install New Package From Repository
2. Assume Yes
3. To Check For Available Updates
4. To Update New Package From Repository
5. Download Package RPM File
[[email protected] ~]# 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.
7. To Uninstall A Package
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
9. View Repository Information
10. Add New Repository
[[email protected] ~]# 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.