DNF (Dandified YUM) can be considered as the updated version of YUM utility. DNF utility stands far better than other package managers when it comes to memory usage, CPU utilization, and various other performance-related factors.
In this tutorial, let us discuss how to use dnf package management tool to install and remove packages with examples.
How to install packages
Before you start installing packages, it's prudent to search and verify whether the package is available. We do this by using the 'search' option as shown below.
dnf search package-name
In this example, we search whether the httpd package is available for installation.
dnf search httpd
Sample Output
# dnf search httpd Last metadata expiration check: 0:15:31 ago on Sun 04 Feb 2018 02:36:58 PM UTC. ===================================================================== Name Exactly Matched: httpd ====================================================================== httpd.x86_64 : Apache HTTP Server ==================================================================== Summary & Name Matched: httpd ===================================================================== radicale-httpd.noarch : httpd config for Radicale drupal8-httpd.noarch : HTTPD integration for drupal8 owncloud-httpd.noarch : Httpd integration for ownCloud openqa-httpd.noarch : openQA httpd (Apache) integration iipsrv-httpd-fcgi.noarch : Apache HTTPD files for iipsrv nextcloud-httpd.noarch : Httpd integration for NextCloud libmicrohttpd-doc.noarch : Documentation for libmicrohttpd anyterm-httpd.x86_64 : Httpd proxy configuration for anyterm gambas3-gb-httpd.x86_64 : Gambas3 component package for httpd mingw32-libmicrohttpd.noarch : MinGW package for libmicrohttpd mingw64-libmicrohttpd.noarch : MinGW package for libmicrohttpd libmicrohttpd-devel.i686 : Development files for libmicrohttpd libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd httpdtap.noarch : Tool for querying httpd using SystemTap scripts
In the above output, you get all the possibilities of the package httpd highlighted.
To install a package, login as root user and run the command below. In this example, we are installing Apache web server.
$ sudo dnf install httpd
How to install packages from a specific repository
With DNF command we can also choose a specific repository for a package installation. Let's first see the available repositories installed in our Fedora 27 system by running the command below.
dnf repolist
Output
Last metadata expiration check: 0:56:19 ago on Sun 04 Feb 2018 02:36:58 PM UTC. repo id repo name status *fedora Fedora 27 - x86_64 54,801 *updates Fedora 27 - x86_64 - Updates 10,909
Let's now install a package called nano from *fedora repository.
$ sudo dnf --enablerepo=*fedora install nano
How to remove packages
DNF also gives you the ability to remove packages that you no longer need on your computer. Similar to the install command all you need to do is identify the package then run the command in your terminal:
$ sudo dnf remove httpd
After this, packages related to httpd will be removed.
Note: Alternatively, we can use the 'erase' option in place of remove which will also un-installs the packages from the system.
dnf erase httpd
The above command removes all packages related to httpd and the output will be the same.
How to remove all packages from a selected repository
To remove all packages from a particular repository, we first need to get its repository id. To do that, we run the command below
dnf -v repolist
Sample Output
Last metadata expiration check: 0:16:19 ago on Thu 08 Feb 2018 11:11:11 AM EAT. Repo-id : fedora Repo-name : Fedora 27 - x86_64 Repo-revision: 1509861107 Repo-updated : Sun 05 Nov 2017 08:51:47 AM EAT Repo-pkgs : 54,801 Repo-size : 57 G Repo-metalink: https://mirrors.fedoraproject.org/metalink?repo=fedora-27&arch=x86_64 Updated : Thu 08 Feb 2018 11:11:11 AM EAT Repo-baseurl : http://mirror.liquidtelecom.com/fedora/fedora/linux/releases/27/Everything/x86_64/os/ (9 more) Repo-expire : 604,800 second(s) (last: Thu 08 Feb 2018 11:11:11 AM EAT) Repo-filename: /etc/yum.repos.d/fedora.repo Repo-id : updates Repo-name : Fedora 27 - x86_64 - Updates Repo-revision: 1518007515 Repo-updated : Wed 07 Feb 2018 04:11:08 PM EAT Repo-pkgs : 11,334 Repo-size : 21 G Repo-metalink: https://mirrors.fedoraproject.org/metalink?repo=updates-released-f27&arch=x86_64 Updated : Thu 08 Feb 2018 11:10:29 AM EAT Repo-baseurl : http://mirror.wbs.co.za/fedora-enchilada/updates/27/x86_64/ (246 more) Repo-expire : 21,600 second(s) (last: Thu 08 Feb 2018 11:10:29 AM EAT) Repo-filename: /etc/yum.repos.d/fedora-updates.repo Total packages: 66,135
As you can see in the output above, we have 2 repo-ids -fedora and updates.
Now you can proceed to remove all packages from a specific repository using the command below
dnf repository-packages repo-id remove
For example, If we want to remove all packages from fedora repository we run
dnf repository-packages fedora remove
Here, fedora is the repo-id.
Note:
For the parent repo-id's, you'll get an alert in the terminal that some packages are system protected. e.g.
dnf repository-packages fedora remove
Sample Output
Problem 1: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev Problem 2: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev Problem 3: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev Problem 4: The operation would result in removing the following protected packages: dnf, kernel-core, systemd, systemd-udev
How to list and remove packages
You can use the dnf list command to get a list of installed and available packages.
To generate a list of installed packages, run the command below:
$ sudo dnf list installed | cat -n
The argument 'cat -n' is used to number the packages on the terminal's output.
Sample Output
1 Last metadata expiration check: 1:22:04 ago on Sun 04 Feb 2018 02:36:58 PM UTC. 2 Installed Packages 3 GeoIP.x86_64 1.6.11-3.fc27 @anaconda 4 GeoIP-GeoLite-data.noarch 2017.10-1.fc27 @anaconda 5 acl.x86_64 2.2.52-18.fc27 @anaconda 6 apr.x86_64 1.6.3-1.fc27 @updates 7 apr-util.x86_64 1.6.1-2.fc27 @updates 8 audit.x86_64 2.7.8-1.fc27 @anaconda 9 audit-libs.x86_64 2.7.8-1.fc27 @anaconda 10 audit-libs-python3.x86_64 2.7.8-1.fc27 @anaconda 11 basesystem.noarch 11-4.fc27 @anaconda 12 bash.x86_64 4.4.12-12.fc27 @anaconda 13 bind99-libs.x86_64 9.9.11-2.fc27 @anaconda 14 bind99-license.noarch 9.9.11-2.fc27 @anaconda 15 bzip2.x86_64 1.0.6-24.fc27 @anaconda 16 bzip2-libs.x86_64 1.0.6-24.fc27 @anaconda 17 c-ares.x86_64 1.13.0-3.fc27 @anaconda
However, if you want to list the available packages for installation, run the command below:
$ sudo dnf list available | cat -n
Again, the argument 'cat -n' is used to number the packages on the terminal's output.
Sample Output
1 Last metadata expiration check: 0:08:29 ago on Mon 05 Feb 2018 02:04:09 PM EAT. 2 Available Packages 3 0ad.x86_64 0.0.22-2.fc27 fedora 4 0ad-data.noarch 0.0.22-1.fc27 fedora 5 0install.x86_64 2.12.1-1.fc27 fedora 6 0xFFFF.x86_64 0.3.9-15.fc26 fedora 7 2048-cli.x86_64 0.9.1-4.fc27 fedora 8 2048-cli-nocurses.x86_64 0.9.1-4.fc27 fedora 9 2048-cli-sdl.x86_64 0.9.1-4.fc27 fedora 10 2ping.noarch 4.1-1.fc27 fedora 11 389-admin.i686 1.1.46-1.fc27.3 fedora 12 389-admin.x86_64 1.1.46-1.fc27.3 fedora 13 389-admin-console.noarch 1.1.12-3.fc27 fedora 14 389-admin-console-doc.noarch 1.1.12-3.fc27 fedora 15 389-adminutil.i686 1.1.23-4.fc27 fedora
Autoremove Option
The 'autoremove' option is used to uninstall packages that were initially installed as dependencies of installed packages but are no longer required by such packages anymore. To uninstall the dependencies, run the command below:
$ dnf autoremove
Thanks for reading and please share your suggestions and thoughts in the below comment section.
Read Also:
Nice post. Do you by chance now how to install *only* the packages from a group and remove everything else? Say, I'd like to revert to Minimal\ Install but I lost track of what I did and didn't, is there a magic command for that?
I love dnf, it's for years I've been flirting with Linux but never really cared for it I guess because I had only dealt with Ubuntu, which I hate, when I discovered dnf in Fedora and the brief period CentOS had it I started using it a lot more. One of my Macs doesn't have macOS anymore--well, two, but the other one is on Windows Server. I think the Deepin desktop is available now for Fedora, if it works fine I'm never coming back! <3
I am trying to learn about dnf and this is by far the best resource that I have yet found. I do have a question. When I run the "dnf search" command, this is what I got which seems far different from what you show above.
$ dnf search httpd
Fedora 26 - x86_64 9.0 MB/s | 53 MB 00:05
Google Chrome 26 kB/s | 3.4 kB 00:00
Opera packages 26 kB/s | 11 kB 00:00
RPM Fusion for Fedora 26 - Free - Updates 829 kB/s | 494 kB 00:00
RPM Fusion for Fedora 26 - Free 3.2 MB/s | 519 kB 00:00
RPM Fusion for Fedora 26 - Nonfree - Updates 677 kB/s | 61 kB 00:00
RPM Fusion for Fedora 26 - Nonfree 1.4 MB/s | 158 kB 00:00
Last metadata expiration check: 0:00:00 ago on Thu 10 Jan 2019 09:01:34 PM EST.
========================= Name Exactly Matched: httpd ==========================
httpd.x86_64 : Apache HTTP Server
======================== Name & Summary Matched: httpd =========================
radicale-httpd.noarch : httpd config for Radicale
drupal8-httpd.noarch : HTTPD integration for drupal8
owncloud-httpd.noarch : Httpd integration for ownCloud
openqa-httpd.noarch : openQA httpd (Apache) integration
iipsrv-httpd-fcgi.noarch : Apache HTTPD files for iipsrv
nextcloud-httpd.noarch : Httpd integration for NextCloud
Why don't I get something similar to what you got? What exactly was it downloading. Thanks!!!
Hi Alias,
It will search entire repository with keyword "httpd" and list all package which have string "httpd".