How to Use the Command 'dnf' (with examples)

How to Use the Command 'dnf' (with examples)

dnf (Dandified YUM) is a robust package management utility for Red Hat Enterprise Linux (RHEL), Fedora, and CentOS, which serves as a replacement for the older yum package manager. It is designed to improve performance, provide better dependency resolution, and enhance the overall user experience in managing software packages. With dnf, users can easily install, upgrade, search, and remove software packages on their system, as well as perform additional package management tasks such as listing installed packages or viewing transaction history. Here’s a detailed exploration of dnf with practical use cases and examples for each.

Use case 1: Upgrade installed packages to the newest available versions

Code:

sudo dnf upgrade

Motivation:

Keeping your system up-to-date is crucial for maintaining security, improving performance, and ensuring system stability. Regular upgrades ensure that you have the latest bug fixes and feature enhancements. Using dnf upgrade is a streamlined way to update all installed packages to their newest versions available in the repositories, without manually checking each package.

Explanation:

  • sudo: Executes the command with administrative privileges, which is necessary for package management activities to affect system-wide changes.
  • dnf: The command-line front-end package management utility used in RHEL-based systems.
  • upgrade: The subcommand which directs dnf to check for available updates and upgrade the currently installed packages to the latest versions.

Example Output:

Dependencies resolved.
================================================================================
 Package           Arch   Version            Repository                   Size
================================================================================
Upgrading:
 nano              x86_64 5.8-1.fc33         updates                     567 k
 git               x86_64 2.31.1-1.fc33      updates                     1416 k

Transaction Summary
================================================================================
Upgrade  2 Packages

Total download size: 1.9 M
Is this ok [y/N]: y

Use case 2: Search packages via keywords

Code:

dnf search keyword1 keyword2 

Motivation:

When users are unsure about the exact package names or want to explore available software based on certain functionality, dnf search becomes a handy tool. By searching via keywords, users can discover packages that fulfill their needs without knowing the exact package name in advance.

Explanation:

  • dnf: Invokes the DNF package manager.
  • search: A subcommand that instructs DNF to perform a search operation through available packages.
  • keyword1 keyword2: Represents the terms or phrases used in the search to find packages whose names or descriptions match the specified keywords.

Example Output:

Last metadata expiration check: 0:05:32 ago on Thu Sep 16 11:23:45 2021.
================================================================================
ndi                              : Network Data & Voice dispatcher
networkmanager                   : Network management service
ntp                              : The Network Time Protocol (NTP) daemon and utilities

Use case 3: Display details about a package

Code:

dnf info package

Motivation:

Having detailed information about a package, such as its version, repository source, size, and other metadata, helps users make informed decisions about installations or upgrades. This can be particularly useful in assessing compatibility with other software components or confirming package origins.

Explanation:

  • dnf: The front-end command-line package management utility.
  • info: A subcommand that provides detailed information about a specified package.
  • package: Placeholder for the name of the package for which details are sought.

Example Output:

Available Packages
Name         : vim
Version      : 8.2
Release      : 1.fc33
Architecture : x86_64
Size         : 1.4 M
Source       : vim-8.2-1.fc33.src.rpm
Repository   : updates
Summary      : The VIM editor

Use case 4: Install a new package

Code:

sudo dnf install package1 package2

Motivation:

Installing new software packages is a routine task for expanding system capabilities, whether for professional needs, gaming, or personal use. dnf install automates this process, resolving dependencies and integrating the software into the system.

Explanation:

  • sudo: Grants necessary root permissions to alter system software.
  • dnf: Calls the package manager to execute tasks.
  • install: The operation to fetch and install specified packages from repositories.
  • package1 package2: Names of one or more software packages to be installed.

Example Output:

Last metadata expiration check: 0:04:02 ago on Thu Sep 16 11:23:45 2021.
Dependencies resolved.
===========================================================================
 Package        Arch    Version      Repository                          Size
===========================================================================
Installing:
 httpd          x86_64  2.4.46-1     updates                             825 k

Transaction Summary
===========================================================================
Install  1 Package

Total download size: 825 k
Installed size: 2.9 M
Is this ok [y/N]: y

Use case 5: Remove a package

Code:

sudo dnf remove package1 package2

Motivation:

Over time, systems can accumulate unnecessary or outdated software, which both consume space and potentially introduce security vulnerabilities. Removing such packages helps streamline the system and alleviate these issues.

Explanation:

  • sudo: Executes the task with the administrative rights required for system changes.
  • dnf: Front-end to conduct package operations.
  • remove: A subcommand that identifies and removes the specified software packages.
  • package1 package2: The names of the packages designated for removal.

Example Output:

Dependencies resolved.
===========================================================================
 Package          Arch    Version         Repository                      Size
===========================================================================
Removing:
 httpd            x86_64  2.4.46-1        @updates                         3.1 M

Transaction Summary
===========================================================================
Remove  1 Package

Freed space: 3.1 M
Is this ok [y/N]: y

Use case 6: List installed packages

Code:

dnf list --installed

Motivation:

For system audits or troubleshooting, knowing exactly which packages are installed can provide valuable insights. This can aid in diagnosing problems or confirming the presence of required software components on a system.

Explanation:

  • dnf: The command-line package manager application.
  • list: Leads dnf to display lists of packages.
  • --installed: An option that filters the list to show only those packages currently installed on the system.

Example Output:

Installed Packages
bash.x86_64                           5.0.17-1.fc33                    @fedora
coreutils.x86_64                      8.32-21                          @fedora
git.x86_64                            2.31.1-1.fc33                    @updates
vim-enhanced.x86_64                   8.2.2156-2                      @updates

Use case 7: Find which packages provide a given command

Code:

dnf provides command

Motivation:

Sometimes users encounter commands without knowing the software package to which they belong. Identifying the source package can expedite troubleshooting and help in installing necessary software components.

Explanation:

  • dnf: Utility for performing package management tasks.
  • provides: Subcommand intended to find packages that offer a specific command or capability.
  • command: The actual command or part of the command in question that users wish to locate the owning package for.

Example Output:

Last metadata expiration check: 0:11:34 ago on Thu Sep 16 11:23:45 2021.
bash-5.0.17-1.fc33.x86_64 : The GNU Bourne Again Shell (Bash)
Repo: @System

Use case 8: View all past operations

Code:

dnf history

Motivation:

Tracking past actions involving software installations, upgrades, or removals can be instrumental in understanding system changes and recovering from errors. The history log lets users audit operations and locate when specific changes were made.

Explanation:

  • dnf: The front-end program for package manipulation.
  • history: Subcommand that retrieves a list of historic package transactions conducted via dnf.

Example Output:

ID     | Command line             | Date and time    | Action(s)      | Altered
================================================================================
    29 | upgrade                  | 2021-09-16 11:25 | Upgrade        |    6   
    28 | remove vim               | 2021-09-15 15:43 | Erase          |    1   
    27 | install vim              | 2021-09-15 15:35 | Install        |    1   
    26 | install httpd            | 2021-09-14 14:22 | Install        |   13  

Conclusion:

The dnf package manager offers a comprehensive suite of tools for efficiently managing software packages on RHEL-based systems. From updating and querying package details to installing, removing software, and auditing operations, dnf provides critical functionality that supports effective and informed system administration. Mastery of these commands can significantly enhance a user’s ability to maintain and optimize their Linux system.

Tags :

Related Posts

How to use the command 'lxc network' (with examples)

How to use the command 'lxc network' (with examples)

LXD, the Linux Containers Daemon, offers a suite of commands to manage containers and the networks they utilize.

Read More
How to use the command 'phpdismod' (with examples)

How to use the command 'phpdismod' (with examples)

The phpdismod command is a powerful tool used to manage PHP extensions on Debian-based operating systems.

Read More
How to use the command 'cpio' (with examples)

How to use the command 'cpio' (with examples)

The cpio command is a versatile tool used on Unix-like systems for handling archive files.

Read More