What it does
dnf is the package manager of RHEL (yum is a link to it). It reads the repositories in /etc/yum.repos.d/, solves dependencies, checks GPG signatures and keeps a history of every transaction that you can undo.
The general settings are in /etc/dnf/dnf.conf (like gpgcheck=1, installonly_limit=3 = keep 3 kernels). Commands that change the system need root; searching and listing do not.
How to write it
dnf [OPTION]... COMMAND [ARGUMENT]...Main parts
installPKG...- Install packages (names, files, URLs,
@group). removePKG...- Remove packages and unneeded dependencies.
reinstallPKG...- Install the same version again.
upgrade[PKG...]- Update packages (all without names).
updateis the same. upgrade-minimal- Only the updates needed for bug and security fixes.
downgradePKG- Go back to an older version.
distro-sync- Make all packages match the repository versions.
check-update- List available updates (exit code 100 if there are some).
autoremove- Remove dependencies nothing needs anymore.
searchWORD...- Search names and summaries (
search all= also descriptions). providesFILE- Find the package that gives a file or command.
infoPKG- Details of a package.
list[installed|available|--upgrades]- List packages.
repolist[all|enabled|disabled]- List repositories.
repoinfo- Details of repositories.
repoquery- Advanced queries (dependencies, files, who requires).
deplistPKG- Dependencies of a package.
grouplist|info|install|remove- Package groups.
history[list|info|undo|redo|rollback]- Past transactions.
updateinfo- Advisories (security, bugfix).
markinstall|removePKG- Mark packages as user-installed or dependency.
swapOLDNEW- Replace one package by another in one step.
makecache- Download the repository indexes.
cleanall|metadata|packages- Remove cached data.
config-manager- Add, enable or disable repositories (plugin).
needs-restarting- Show if a reboot or service restart is needed (plugin).
downloadPKG- Download the .rpm without installing (plugin).
shell- Interactive dnf shell.
Options 50
Most used
Answers and output
Repositories
Which packages
Security updates
Downloads and others
Nothing matches this filter.
Examples 15
$ run as a normal user# run as root (or with sudo)
1Install a package
dnf install -y httpdDependencies come too.
2Find the package of a command
dnf provides '*/semanage' policycoreutils-python-utils-3.8-1.el10.noarch : SELinux policy core python utilitiesThen install that package.
3Search for software
dnf search nmapSearches names and summaries.
4Update everything
dnf upgrade -yNew kernels are added next to the old ones.
5Only security updates
dnf upgrade --security -y dnf updateinfo list --securityPatch fast with less risk.
6Install a local RPM file with dependencies
dnf install -y ./tool-1.2-1.el10.x86_64.rpmBetter than rpm -i: missing dependencies come from the repositories.
7Show repositories and enable one for a command
dnf repolist all dnf install -y --enablerepo=codeready-builder-for-rhel-10-x86_64-rpms ninja-buildThe repo is used only for this command.
8Add a repository file
dnf config-manager --add-repo http://repo.example.com/rhel10/AppStreamWrites a .repo file in /etc/yum.repos.d/.
9Install a group
dnf group install -y "Development Tools"Many packages for one job.
10Undo the last change
dnf history dnf -y history undo lastRemoves what the last transaction installed.
11Show all versions and install an older one
dnf list --showduplicates httpd dnf install -y httpd-2.4.62-1.el10Name-version-release selects the version.
12Keep a package on its version
echo "excludepkgs=kernel*" >> /etc/dnf/dnf.confOr use the versionlock plugin. Remove it later or you miss security fixes.
13Is a reboot needed after updates?
dnf needs-restarting -rKernel or glibc updates need a reboot.
14Download packages for an offline server
dnf download --resolve --destdir=/tmp/pkgs nmapCopy the folder to the server and install with dnf install.
15Clean the cache after repository problems
dnf clean all; dnf makecacheFixes errors from old indexes.
Nothing matches this filter.
Watch out
- The exam system has no Red Hat repositories: first create the .repo file.
--nogpgcheckandgpgcheck=0trust any package. Only in labs.dnf removealso removes dependencies; read the list before you say yes.
Files
/etc/dnf/dnf.conf- General settings.
/etc/yum.repos.d/*.repo- Repository definitions.
/var/cache/dnf/- Downloaded indexes and packages.
/var/log/dnf.log- Log of dnf actions.
Exit codes
0 | Done (check-update: no updates). |
1 | Error. |
100 | check-update: updates are available. |
200 | Another dnf holds the lock. |