DNF is the package manager that was earlier used in Fedora as a default package manager but with the start of RHEL 8, it is now available a package manager choice along with YUM. In the future, it might be completely removed from RHEL versions. Yum has some problems associated with it, The problems like poor performance, high memory usage, slowness for dependency resolution, etc. All these problems have been resolved with DNF.

Recommended Read: Examples on how to use YUM command in Linux

Also Read: Examples on how to use RPM command in Linux

In this tutorial, we will learn to use DNF command in Linux,

Examples of DNF command in Linux

1- Install package and depend­encies

To install a package & its related dependencies, the command is,

# dnf install packa­ge_­name

If required, we can install local package (rpm package) and all its depend­encies with the following command,

# dnf install /path­/to­/lo­cal­/rpm

To reinstall a package, command is

# dnf reinstall packa­ge_­name

2- Install a package for which we only have a file

If we don’t know the package name & want to install the package for which we only have file (maybe config file), then we can use the following command to install it,

# dnf install /path­/to­/fi­le

3- Upgrade packages

The command to upgrade all system packages is,

# dnf upgrade

To update packages to major patchset and security

# dnf upgrad­e-m­ini­mal

To check if updates are available for packages,

# dnf check-­upd­ate

4- Downgrade packages

To downgrade the installed packages to older versions, the command is

# dnf downgrade packa­ge_­name

5- Uninstall or remove a package

The command to remove or uninstall a package from the system is,

# dnf remove packa­ge_­name

# dnf erase package_name

& if we have some orphaned packages (like some replaces packages that are not required anymore, ex old kernels etc) on our system that we want to remove, we can use the following command,

# dnf autore­move

6- Overview of how many groups are installed and available

To get the list of how many group packages are installed & how many are available, we can use

# dnf group summary group

To get the list of all packages for a group, we can use the command,

# dnf group info group

To only check a particular group,

# dnf group list group_name

7- Install group

Command to install the group is,

# dnf group install –with­-op­tional group_name

8- Remove a group

To remove an installed group of packages, use

# dnf group remove group_name

9- Upgrade a single group

To upgrade the packages from the group and upgrades the group itself

# dnf group upgrade group

10- Update all packages

To update packages to the latest version, execute the following command,

# dnf distro­-sync

11- Check information a package

To show info of packa­ge_­name, run

# dnf info packa­ge_­name

12- Check which package provides a file

To show which package provides /path­/to­/file

# dnf provides path/­to/­file

13- Perform a search term for a package

To search for term in package name and summary

# dnf search term

14- Get dnf history

To get list of all dnf transa­ction’s history

# dnf history list

History shows transaction id, to get information for a particular transaction,

# dnf history info trans­act­ion_id

To redo particular trans­action from history, run,

# dnf history redo trans­act­ion_id

To rollback a particular transaction,

# dnf history rollback trans­act­ion_id

To undo a transaction,

# dnf history undo trans­act­ion_id

15- Show user-installed packages outside dnf

To only show all instal­l only packages, packages installed outside of DNF and packages not installed as a dependency,

# dnf history userin­sta­lled

16- List repositories

To show enabled repolist,

# dnf repolist –enabled

To show disabled repolist,

# dnf repolist –disabled

To list all repos, enabled, disabled & all known repos

# dnf repolist –ena­ble­d|­–­dis­abl­ed­|-­-all

17- Search repo for selected packages

To search the available DNF reposi­tories for selected packages,

# dnf repoqu­ery

18- Add a remote repository

To add a remote repository to the system,

# dnf config­-ma­nager –add-­rep­o=­URL add remote repository

19- Download a package

To only download a package & not install it on the system, run

# dnf download package_name

20- List packages

To list installed packages on the system,

# dnf list –installed

List available packages,

# dnf list –available

List recent packages,

# dnf list –recent

List all packages,

# dnf list –all

We now end our tutorial on how to use DNF command in Linux. Please do let us know your suggestions, questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.