dnf Command – Install and Manage Packages in CentOS / Fedora

In this tutorial we are going to learn how to use dnf command to install and manage packages in RPM-based Linux distributions.

The dnf command is the improved version of the yum package manager which is used in Redhat based Linux distributions. Currently Fedora use dnf command as its package manager and we expect the next major release of Redhat and CentOS will use dnf command as the their software installer.

Install Packages using dnf command

The main purpose of the dnf command is to install Software packages on RPM-based Linux distributions(RedHat/ CentOS/ Fedora).

dnf install package-name

Package-name is the name of the software or package you want to install.

Example 1

For example, we can use dnf command to install Apache httpd server on Redhat based Linux Distributions.

dnf install httpd

This will install the Apache httpd server on RPM-based Linux distributions.

Install Packages using dnf command

Example 2

We can also install multiple packages at once using the dnf command.

dnf install httpd php

As per the Above example, Both Apache Web Server and PHP will be installed.

Remove Packages with dnf command

To remove a package, use dnf remove followed by the package name.

dnf remove package-name

Along with the specified package, The dnf remove command also removes all dependency packages that are no longer needed.

Example

dnf remove httpd

This will remove the Apache httpd Server and the dependency packages from the Fedora/CentOS Server.

Remove Multiple packages with dnf command

The dnf command can remove multiple packages at once.

dnf remove httpd php

This will remove both Apache web Server and php software from the CentOS/Fedora System.

Update Packages with dnf command

To update package or softwares, use dnf update command followed by the name of the package.

dnf update <package-name>

Example - Update Firefox using dnf command

Following example shows how to update Firefox on Fedora using dnf update command.

dnf update firefox

This will update the Firefox web browser.

Update Multiple packages.

It is also possible to update multiple packages at once with dnf command.

dnf update <package 1> <package 2>

Example

dnf update putty firefox

As per the above example, Both putty and Firefox will be updated in your Fedora Machine.

Check for Updates with dnf check-update command

We can search Available software updates with check-update option.

dnf check-update <package-name>

If no <package-names> are given, dnf command will check for the all available updates in the Linux System.

Example 1 - Check Update for the firefox

dnf check-update firefox

Check for Updates with dnf check-update command

Example 2 - grep the search result

In the following example, we filter the search result using the Linux grep command.

dnf check-update | grep flash

We did not specify a package name, hence dnf command will search for the all updates available. But we will filter the search result using the grep command to check updates related to the flash player.

Search Packages and softwares using dnf command

The dnf search command will search for the available packages that match the given keyword.

dnf search <keywords>

Example 1

dnf search java

As per the above example, dnf command will search for the available packages that related the java.

Search Packages and softwares using dnf command

Example 2

dnf search php http

This time we have given multiple keywords for search. The dnf command will search softwares for both keyword php and http.

List Installed Packages

The dnf list installed command list all installed packages on your CentOS / Fedora System.

dnf list installed

This is really helpful, when you want to find out whether a certain software is already installed.

Example

dnf list installed

This will list all installed packages on your CentOS System.

We can filter the output using the grep command.

dnf list installed | grep php

This will tell us whether php is installed or not.

List Installed Packages dnf command

Get Information About packages

The dnf info command will display information about given package.

dnf info package

Information includes Version, Release, Size, Description and etc. If packaged is already installed, dnf command will show available updates for the package.

Example

dnf info nginx

Will display the information about the Nginx Webserver.