Table of Contents
Introduction
DNF is the command line package manager used by Fedora, CentOS Stream, and recent Red Hat Enterprise Linux (RHEL) systems. It installs, updates, and removes software by talking to configured repositories, resolving dependencies for you. In this chapter you will focus on the basics of using DNF as a regular user and with administrative privileges, without going into general package management concepts that are discussed elsewhere.
Basic DNF usage pattern
DNF commands follow a simple pattern: you call dnf, specify an action like install or remove, and then name one or more packages. For operations that modify the system you run the command with sudo so it has permission to change installed software.
For example, to install a package named htop you would run:
sudo dnf install htopDNF will contact the repositories, work out which additional packages are needed, show you what will be done, and then ask for confirmation.
You can see a brief built in summary of DNF’s options with:
dnf help
This does not require sudo because it does not change the system.
Always use sudo with DNF when you are installing, removing, or updating packages, and avoid running DNF as the root user directly if possible.
Installing packages
The most common operation in DNF is installing new software. The basic form is:
sudo dnf install PACKAGE_NAMEIf you already know the exact package name, you can provide it directly. For instance, to install Git:
sudo dnf install git
If DNF suggests additional packages as dependencies, it will show you a summary and ask Is this ok [y/N]:. Press y and Enter to confirm. If you answer N or just press Enter without typing y, the operation will be canceled.
You can install multiple packages in a single command by listing them all:
sudo dnf install vim nano curlIf the package is already installed and up to date, DNF will tell you so and skip reinstalling it, unless you explicitly request a reinstall.
Searching for software
If you do not know the exact name of a package, DNF can search for it. The simplest search looks at package names and a few basic fields:
dnf search KEYWORD
For example, to search for packages related to curl:
dnf search curlThis will list matching packages with short descriptions. Use it when you have a general idea of what you want but not the precise package name.
To find more detailed information about a specific package, you can use:
dnf info PACKAGE_NAME
This shows the version, repository, size, summary, description, and whether it is already installed. If you see Available Packages, it means the package exists in a repository but is not installed yet. If you see Installed Packages, it is already on your system.
Updating software and the system
DNF can update individual packages or your whole system. To update a specific package, run:
sudo dnf update PACKAGE_NAME
On recent Fedora and RHEL systems you can also use upgrade which is the recommended form:
sudo dnf upgrade PACKAGE_NAMETo update the entire system to the latest versions of all installed packages, use:
sudo dnf upgradeDNF will first refresh repository information if needed, examine what has changed, and then present you with a list of packages to upgrade along with the total size of downloads. Confirm the operation to proceed.
If you only want to refresh the list of available package versions without actually installing anything, use:
sudo dnf check-updateThis checks if updates exist and prints them but does not alter your system.
Before accepting large upgrades, especially on production or important systems, read the list of packages carefully to understand what will change.
Removing packages
To remove a package and its unneeded dependencies, use:
sudo dnf remove PACKAGE_NAME
For example, to remove nano:
sudo dnf remove nanoDNF will show you all packages that are going to be removed. This can include other packages that depend on the one you named. Always review this list when removing software so you do not accidentally remove something important.
After removal, some dependencies might become unused. DNF can detect and remove them automatically, which is covered in the cleaning section.
Listing installed packages
DNF can show you which packages are installed. The simplest list is:
dnf list installed
This can be very long, so you might want to filter it. For example, to list only installed packages related to python:
dnf list installed 'python*'
Here the single quotes prevent the shell from interpreting the * character, which lets DNF handle the pattern.
You can also check if a particular package is installed using:
dnf list installed PACKAGE_NAMEIf there is no output, the package is not installed.
Viewing package information and files
The dnf info command gives you details about a package, including the repository it comes from and a description.
For installed packages, you might want to see which files they provide. On systems that include the required plugins, you can use:
dnf repoquery -l PACKAGE_NAMEThis lists the files that belong to the package. It is useful if you want to know where a program installed its binaries, libraries, or documentation.
If repoquery is not available by default, your distribution may provide it through a DNF plugin package, which you can then install with DNF itself.
Managing DNF caches and cleaning up
DNF keeps a cache of downloaded package metadata and package files to speed up future operations. Over time this cache can grow large, so DNF offers several cleaning options.
To remove old metadata from the cache but keep downloaded packages, use:
sudo dnf clean metadataTo remove cached packages, use:
sudo dnf clean packagesTo clean everything that DNF keeps in its cache, including metadata and packages, run:
sudo dnf clean allIn addition to cleaning the cache, you can remove unused dependencies that were installed automatically but are no longer needed by any installed package. This is done with:
sudo dnf autoremoveDNF will show which packages it considers no longer needed. Check the list before confirming.
Use sudo dnf autoremove carefully. Review the list of packages to make sure nothing essential is being removed, especially if you manually installed some libraries or tools that DNF might treat as unused.
Working with package groups
Fedora and RHEL organize some software into groups that represent a collection of related packages, such as tools for a specific task or environment. DNF can operate on these groups.
To list available groups, run:
dnf group list
You will see groups such as Development Tools or desktop environments. To install a group, use:
sudo dnf group install "GROUP NAME"For example, to install general development tools:
sudo dnf group install "Development Tools"Similarly, you can remove a group of packages with:
sudo dnf group remove "GROUP NAME"Group operations are convenient when you want a complete set of tools for a purpose without selecting each package individually.
Reverting and history
DNF keeps a history of its transactions, which records what was installed, updated, or removed. You can view this history and sometimes revert changes.
To see the history, use:
sudo dnf historyThis prints a list of past transactions with an ID number, the command type, and the date. To see details about a specific transaction, use:
sudo dnf history info ID
Replace ID with the number from the history list. This shows exactly which packages were involved.
If a recent update caused problems, DNF can attempt to undo a transaction. For example:
sudo dnf history undo IDThis tells DNF to reverse what was done in that transaction as far as possible. Not every change can be undone perfectly, but this can help recover from some mistakes.
Use dnf history undo only when you understand which transaction you are reversing and which packages will be changed. Always inspect the summary DNF prints before confirming.
Handling repositories at a basic level
DNF relies on repositories, which are collections of packages defined in configuration files. You normally do not need to edit these manually as a beginner, because Fedora and RHEL provide sensible defaults and tools that add additional repositories for you.
To see which repositories are enabled, use:
dnf repolistThis prints the IDs and names of repositories DNF is currently using. If a package you want cannot be found, it might not exist in any enabled repository. On Fedora, some kinds of software may require enabling additional official or third party repositories through graphical tools or specific DNF commands, which are typically documented by the provider of that repository.
As a beginner, you should avoid manually editing repository configuration files until you are familiar with how your distribution manages them.
Working without confirmation
Sometimes you might want to script DNF commands or run them non interactively. DNF offers a way to automatically answer "yes" to prompts.
To do this, add the -y or --assumeyes option:
sudo dnf -y upgradeThis will proceed without asking for confirmation. It is useful for automated maintenance, but it also makes it easy to overlook important changes.
Avoid using dnf -y on systems where you cannot afford unexpected changes, unless you also have a reliable backup and understand the risks.
Summary
DNF is the central tool for managing software on Fedora and RHEL based systems. You now know how to install, search for, update, and remove packages with DNF, how to list installed software, view package details, clean caches, work with package groups, inspect history, and handle basic repository questions. With these skills you can manage most everyday software tasks on a Fedora or RHEL system from the command line.