Linux Command Reference ยท Packages and Services
Linux dnf and yum commands
Reference for the Linux dnf and yum commands: install, update, remove, search and inspect packages on Fedora, RHEL, Rocky and Alma, with repositories, groups and history.
dnf is the package manager of Fedora, RHEL 8 and later, Rocky Linux, AlmaLinux and CentOS Stream. It downloads RPM packages from configured repositories, resolves dependencies, and installs, upgrades or removes everything in one transaction. yum is its predecessor on RHEL 7 and CentOS 7; on modern systems yum is just a link to dnf, and nearly all commands work with either name.
The actual package files are handled by rpm; dnf adds downloading, dependency solving and repository metadata. Changing the system needs root (sudo); queries do not.
sudo dnf install PACKAGE... dnf search WORD dnf info PACKAGE
Try it
The sandbox is Debian-based and has neither dnf nor a network, so this block is read-only:
$ sudo dnf install -y tree Dependencies resolved. Package Arch Version Repository Size tree x86_64 2.1.0-4.fc40 fedora 57 k Installed: tree-2.1.0-4.fc40.x86_64 Complete! $ dnf provides '*/bin/dig' bind-utils-32:9.18.28-1.fc40.x86_64 : Utilities for querying DNS name servers Filename : /usr/bin/dig $ dnf history ID | Command line | Date and time | Action(s) | Altered 4 | install -y tree | 2025-03-02 09:14 | Install | 1
The shape of an RPM name is worth reading by eye. This block splits one into its parts:
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
dnf [OPTIONS] COMMAND [ARGUMENTS]
| Command | Description |
|---|---|
install PKG... |
Install packages, or a local .rpm file; also @group for a package group. |
remove PKG... (erase) |
Remove packages and the dependencies nothing else needs. |
upgrade [PKG...] (update) |
Upgrade everything, or the listed packages. |
check-update |
List available updates without applying them (exit status 100 if any). |
search WORD |
Search names and summaries. |
info PKG |
Show details of a package. |
provides PATH (whatprovides) |
Find the package that provides a file or capability. |
list [installed|available|updates] |
List packages. |
repolist |
Show enabled repositories (--all includes disabled ones). |
history, history undo N |
Show or reverse earlier transactions. |
group list, group install NAME |
Work with package groups. |
autoremove |
Remove leftover dependencies. |
clean all, makecache |
Delete cached metadata; rebuild it. |
download PKG |
Fetch the RPM without installing (a plugin on some versions). |
| Common option | Description |
|---|---|
-y |
Assume yes. |
--enablerepo=ID, --disablerepo=ID |
Turn a repository on or off for one command. |
--exclude=PATTERN |
Leave out matching packages. |
--setopt=KEY=VALUE |
Override one configuration value. |
--refresh |
Force fresh metadata. |
Returns: 0 on success, 1 on an error, and for check-update 100 when updates exist and 0 when there are none.
Usage notes
- No separate
updatestep.dnfrefreshes its metadata automatically when it is stale (the cache is valid for a while, set bymetadata_expire);dnf makecacheor--refreshforces it. upgradeandupdateare the same in dnf. In scripts,dnf -y upgradeis the idiom.- Repositories are
.repofiles in/etc/yum.repos.d/. Enterprise Linux needs EPEL (dnf install epel-release) for many popular extras; third-party repositories should be added only from vendors you trust, with GPG checking on (gpgcheck=1). - Find the package for a command.
dnf provides '*/bin/NAME'is more reliable than guessing the package name. - Undo a mistake.
dnf history undo Nreverses transactionN;dnf history info Nshows what it did. - Modules (RHEL 8/9 AppStreams) offer parallel versions, for example
dnf module enable nodejs:20; they were removed from newer Fedora. - Security updates.
dnf upgrade --securityapplies only advisories marked as security fixes on distributions that publish them. yumon old systems has nodnf history undo-style rollback in some versions, and its option names differ slightly; checkman yum.dnf5(Fedora 41 and later) rewrites the tool in C++ with mostly identical commands but faster output; scripts that parse text should be tested after upgrading.
Related
rpm,aptandapt-get,dpkg,pacman,systemctl- Lessons: Packages and Services, Hardening