How to use DNF package manager command in Linux

DNF is next generation package manager replacing yum in rpm based Linux distributions. It was first introduced in Fedora 18, is default package manager in Fedora. Yum 4 is based on DNF package manager on Redhat 8.

Command list DNF

Check Version of DNF install and get help on DNF command

To check the version of DNF package installed, use command 

Syntax

dnf --version

output will give version dnf package installed

To get help on DNF command use “help” switch

Syntax

dnf help

This will list all main commands of dnf

To get help on specific command, use

Syntax

dnf help <command name>

Example

dnf help install

Manage packages with DNF command

DNF command basic usage is installation, update, installing, removing, list and search packages.

Get Package information

Syntax

dnf info <package name>

Example

dnf info vsftp

Install Package with DNF command

To install single package use below command

Syntax

dnf install httpd

DNF can install multiple packages in a single go, use switch install followed by package name. All package will be separated by space 

Syntax 

dnf install httpd vsftpd 

Note: DNF command will require confirmation from user for each package installation, for which key ”y” has to be pressed. Alternatively you can provide confirmation at the time of entering command.

Example

dnf install httpd vsftpd -y

This will install all packages without any user intervention.

List Packages with DNF command

For listing of package three options are available. You can list all packages i.e. installed and available, listing of available packages and listing of  installed packages.

To list all packages use command

Syntax

dnf list

To list installed packages use command

Syntax

dnf list installed

To list available packages for installation from all enabled repositories use

Syntax

dnf list available  

Check updates of packages with DNF command 

 To check for availability updates of installed packages use command

Syntax

dnf check-update
or
dnf list updates 

To check updates of a single installed package

Syntax

dnf list <package-name>

Example 

dnf update vsftpd

Update package with DNF command

Update can be done for single or multiple or all  installed package. To update single package use command

Syntax

dnf update <package name>

Example

dnf update vsftpd

For updating multiple packages with single command use

Syntax

dnf update <package-name1> <package-name2>

Example

dnf update vsftpd httpd

To update all packages for which updates are available use command

Syntax

dnf update

Reinstall packages with DNF command

If you are encountering problems in any of installed packages, you can reinstall it to check for issues in current install.

Syntax

dnf reinstall <package-name>

Example

dnf reinstall vsftpd

Remove/Erase a package with DNF command

To remove or erase package using DNF command use

Syntax

dnf remove <package-name>
OR
dnf erase <package-name> 

Example

dnf remove nano
OR
dnf erase nano 

Clear cache using DNF command

To clear cache of incomplete download , error or out of date packages use command

Syntax

dnf clean all

Manage groups with DNF command

Packages are grouped as per their usage in system like Graphical Administration Tools, Security Tools, System Administration Tools etc. When group is installed all dependent packages will also be installed.

List all available package group

To list all available packages use command

Syntax

dnf grouplist

Install a package group

Packages can be installed in a group via command

Syntax

dnf groupinstall 'Package name'

Example

dnf groupinstall 'Security Tools'

Remove a package group

Syntax

dnf groupremove 'Package name'

Example 

dnf groupremove 'Security Tools'

Update a package group

Syntax

dnf groupupdate 'Package name'

Example

dnf groupupdate 'Security Tools'

Managing Repositories to DNF

A repository can be manually added by creating a package.repo file under /etc/yum.repos.d/ directory. Also it can be added using DNF

View repositories

To view all enabled repositories use command

Syntax 

dnf repolist

Adding repositories

To add new repository to existing list of repository use command 

Syntax 

dnf config-manager --add-repo repository_url

Enable repositories

To enable an added repository use command

Syntax

dnf config-manager --set-enabled <repo-id>

To ensure repository is enable use view command.

Disable repositories

To disable an existing repository use command

Syntax

dnf config-manager --set-disabled  <repo-id>