Skip to content
Latchkey

dnf install -y: Packages on Fedora and RHEL

dnf install -y installs packages non-interactively on Fedora, RHEL 8+, Rocky, and AlmaLinux.

dnf replaced yum as the RPM front end. In CI you want -y for no prompts and often the weak-deps setopt to keep images lean.

What it does

dnf install resolves and installs the named packages plus dependencies from the enabled repositories. -y assumes yes. Setting install_weak_deps=False skips Recommends/Supplements, the dnf equivalent of apt --no-install-recommends.

Common usage

Terminal
dnf install -y --setopt=install_weak_deps=False \
  git curl ca-certificates
# pin an exact version
dnf install -y nginx-1.24.0
# then shrink the image
dnf clean all && rm -rf /var/cache/dnf

Options

FlagWhat it does
-y / --assumeyesAnswer yes to all prompts
--setopt=install_weak_deps=FalseSkip weak (Recommends) dependencies
--nodocsDo not install documentation files
--enablerepo / --disablerepo <id>Toggle a repo for this command
--allowerasingPermit removing packages to resolve conflicts
pkg-versionInstall a specific version

In CI

Combine --setopt=install_weak_deps=False and --nodocs to trim container images, then dnf clean all and rm -rf /var/cache/dnf in the same layer. Pin versions for reproducibility.

Common errors in CI

"No match for argument: <pkg>" means the package name is wrong or its repo is not enabled; check with dnf search or --enablerepo. "Error: Unable to find a match" is the same cause. "Failed to download metadata for repo '<id>'" means a repo URL is unreachable or the GPG key/mirror is broken. "Curl error (60) ... SSL certificate problem" means CA certs are missing; install ca-certificates.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →