How to Install and Remove Packages with DNF in Fedora

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 article, 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

[[email protected] ~]# 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

Sample output

Running transaction
  Preparing        :                                                                                                                                                1/1
  Installing       : apr-1.6.3-1.fc27.x86_64                                                                                                                        1/8
  Running scriptlet: apr-1.6.3-1.fc27.x86_64                                                                                                                        1/8
  Installing       : apr-util-1.6.1-2.fc27.x86_64                                                                                                                   2/8
  Running scriptlet: apr-util-1.6.1-2.fc27.x86_64                                                                                                                   2/8
  Installing       : httpd-tools-2.4.29-1.fc27.x86_64                                                                                                               3/8
  Installing       : fedora-logos-httpd-28.0.2-1.fc27.noarch                                                                                                        4/8
  Installing       : mailcap-2.1.48-2.fc27.noarch                                                                                                                   5/8
  Running scriptlet: httpd-filesystem-2.4.29-1.fc27.noarch                                                                                                          6/8
  Installing       : httpd-filesystem-2.4.29-1.fc27.noarch                                                                                                          6/8
  Installing       : mod_http2-1.10.13-1.fc27.x86_64                                                                                                                7/8
  Installing       : httpd-2.4.29-1.fc27.x86_64                                                                                                                     8/8
  Running scriptlet: httpd-2.4.29-1.fc27.x86_64                                                                                                                     8/8
  Verifying        : httpd-2.4.29-1.fc27.x86_64                                                                                                                     1/8
  Verifying        : httpd-filesystem-2.4.29-1.fc27.noarch                                                                                                          2/8
  Verifying        : httpd-tools-2.4.29-1.fc27.x86_64                                                                                                               3/8
  Verifying        : mailcap-2.1.48-2.fc27.noarch                                                                                                                   4/8
  Verifying        : apr-1.6.3-1.fc27.x86_64                                                                                                                        5/8
  Verifying        : apr-util-1.6.1-2.fc27.x86_64                                                                                                                   6/8
  Verifying        : mod_http2-1.10.13-1.fc27.x86_64                                                                                                                7/8
  Verifying        : fedora-logos-httpd-28.0.2-1.fc27.noarch                                                                                                        8/8

Installed:
  httpd.x86_64 2.4.29-1.fc27                  apr.x86_64 1.6.3-1.fc27                apr-util.x86_64 1.6.1-2.fc27       fedora-logos-httpd.noarch 28.0.2-1.fc27
  httpd-filesystem.noarch 2.4.29-1.fc27       httpd-tools.x86_64 2.4.29-1.fc27       mailcap.noarch 2.1.48-2.fc27       mod_http2.x86_64 1.10.13-1.fc27

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

Sample output

Install  1 Package

Total download size: 560 k
Installed size: 2.1 M
Downloading Packages:
nano-2.8.7-1.fc27.x86_64.rpm                                                            5.6 MB/s | 560 kB     00:00
------------------------------------------------------------------------------------------------------------------------
Total                                                                                   1.3 MB/s | 560 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                1/1
  Installing       : nano-2.8.7-1.fc27.x86_64                                                                       1/1
  Running scriptlet: nano-2.8.7-1.fc27.x86_64                                                                       1/1
  Verifying        : nano-2.8.7-1.fc27.x86_64                                                                       1/1

Installed:
  nano.x86_64 2.8.7-1.fc27

Complete!

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

Sample Output

Running transaction
  Running scriptlet: systemd                                                                                        1/1
  Preparing        :                                                                                                1/1
  Running scriptlet: httpd-2.4.29-1.fc27.x86_64                                                                     1/8
  Erasing          : httpd-2.4.29-1.fc27.x86_64                                                                     1/8
  Running scriptlet: httpd-2.4.29-1.fc27.x86_64                                                                     1/8
  Erasing          : mailcap-2.1.48-2.fc27.noarch                                                                   2/8
  Erasing          : httpd-filesystem-2.4.29-1.fc27.noarch                                                          3/8
  Running scriptlet: httpd-filesystem-2.4.29-1.fc27.noarch                                                          3/8
  Erasing          : fedora-logos-httpd-28.0.2-1.fc27.noarch                                                        4/8
  Erasing          : httpd-tools-2.4.29-1.fc27.x86_64                                                               5/8
  Erasing          : apr-util-1.6.1-2.fc27.x86_64                                                                   6/8
  Running scriptlet: apr-util-1.6.1-2.fc27.x86_64                                                                   6/8
  Erasing          : apr-1.6.3-1.fc27.x86_64                                                                        7/8
  Running scriptlet: apr-1.6.3-1.fc27.x86_64                                                                        7/8
  Erasing          : mod_http2-1.10.13-1.fc27.x86_64                                                                8/8
  Running scriptlet: mod_http2-1.10.13-1.fc27.x86_64                                                                8/8
  Verifying        : mod_http2-1.10.13-1.fc27.x86_64                                                                1/8
  Verifying        : httpd-2.4.29-1.fc27.x86_64                                                                     2/8
  Verifying        : apr-1.6.3-1.fc27.x86_64                                                                        3/8
  Verifying        : apr-util-1.6.1-2.fc27.x86_64                                                                   4/8
  Verifying        : httpd-filesystem-2.4.29-1.fc27.noarch                                                          5/8
  Verifying        : httpd-tools-2.4.29-1.fc27.x86_64                                                               6/8
  Verifying        : mailcap-2.1.48-2.fc27.noarch                                                                   7/8
  Verifying        : fedora-logos-httpd-28.0.2-1.fc27.noarch                                                        8/8

Removed:
  httpd.x86_64 2.4.29-1.fc27                apr-util.x86_64 1.6.1-2.fc27     httpd-tools.x86_64 2.4.29-1.fc27
  mod_http2.x86_64 1.10.13-1.fc27           apr.x86_64 1.6.3-1.fc27          fedora-logos-httpd.noarch 28.0.2-1.fc27
  httpd-filesystem.noarch 2.4.29-1.fc27     mailcap.noarch 2.1.48-2.fc27

Complete!

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
Bobbin Zachariah 3:00 am

About Bobbin Zachariah

Founder of LinOxide, passionate lover of Linux and technology writer. Started his career in Linux / Opensource from 2000. Love traveling, blogging and listening music. Reach Bobbin Zachariah about me page and google plus page.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.