CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Packages & Services / dnf

dnf

Manage packages on Amazon Linux 2023, RHEL and Fedora

Beginnerpackagesrhelamazon-linux

dnf is the package manager on Amazon Linux 2023, RHEL 8+, Rocky, Alma and Fedora. It reads repository metadata, solves dependencies, downloads RPMs, checks their signatures and installs them through rpm in one transaction you can later inspect and undo.

Syntaxdnf [OPTIONS] install | remove | upgrade | check-update | search | info | provides | list | history | repolist [ARGS]...

Watch it run

A new EC2 instance on Amazon Linux 2023 needs nginx. Install it and read the transaction before saying yes.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
sudo dnf install nginx

dnf refreshes metadata if it has expired, solves dependencies and prints the transaction. Unlike apt, the default answer is N: just pressing Enter cancels.

Anatomy of a command

$
commandsudo

Installing writes the RPM database and system files, so it needs root. search, info and list work without it.

How it works

dnf reads the repo definitions in /etc/yum.repos.d/*.repo, downloads each repo's repomd.xml and the primary, filelists and other metadata it points to, and caches them in /var/cache/dnf. The metadata expires (metadata_expire), so dnf refreshes it on its own and prints 'Last metadata expiration check'. libsolv, a SAT solver, turns your request plus the installed rpmdb into a transaction: installs, upgrades, removals and weak dependencies. dnf downloads the RPMs, checks their GPG signatures against keys imported from gpgkey=, then hands the transaction to librpm. rpm runs a test transaction (file conflicts, disk space) before running scriptlets and writing files and the rpmdb in /var/lib/rpm. Each transaction is recorded in the history database under /var/lib/dnf, which is what dnf history undo replays in reverse. On Amazon Linux 2023 the repos are locked to a release version, so dnf upgrade only moves within it.

Options you'll actually use

install PKG|FILE.rpmInstall packages or a local RPM, resolving dependencies from repos
remove PKGRemove packages plus unused dependencies (clean_requirements_on_remove)
upgrade [PKG]Upgrade everything, or the named packages
check-updateList available updates; exit code 100 means updates exist
search WORDSearch package names and summaries
info PKGVersion, size, repo, license and description
provides PATHWhich package ships a file or command (*/bin/dig)
list installed|availableList packages, optionally filtered by a glob
history / history undo NShow past transactions / reverse one
repolistShow enabled repositories
-yAssume yes
--securityLimit upgrade/check-update to security advisories
clean all / makecacheDrop cached metadata / download it again

Common mistakes

Pressing Enter at 'Is this ok [y/N]'

The default is No, so the transaction is cancelled ('Operation aborted.').

Type y, or use -y in automation
if dnf check-update; then echo up to date; fi

check-update exits 100 when updates exist, so the test treats 'updates pending' and real errors the same way.

dnf check-update -q; rc=$?; [ $rc -eq 100 ] && echo updates pending
Expecting the service to run after dnf install nginx

RPM packages don't start services on install; the unit is installed but inactive and disabled.

sudo systemctl enable --now nginx
Adding EPEL to Amazon Linux 2023 to get a missing package

AL2023 isn't built against EPEL's RHEL ABI; mixing repos can pull incompatible libraries.

Check dnf provides, use the vendor's AL2023 repo, or run the tool in a container

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    The sandbox is Ubuntu (no dnf). Write the dnf command that installs nginx without weak dependencies and without a prompt.

  2. 2

    Write a shell snippet that runs dnf check-update and prints 'patched', 'updates pending' or 'error'.

  3. 3

    On Ubuntu, the equivalent of 'dnf provides */bin/ss' for an installed file is dpkg -S. Find which package owns /usr/bin/ss in the sandbox.

  4. 4

    Read this and explain it: 'Error: Unable to find a match: ngnix'. What two things do you check?

Related commands

yumThe classic RPM package manager (and what it is today)rpmQuery, verify and install RPM packages directlyaptInstall, upgrade and remove packages on Debian and UbuntusystemctlStart, stop, enable and inspect systemd services
PreviousaptNextyum
Linux / Packages & Services / dnf

dnf

Manage packages on Amazon Linux 2023, RHEL and Fedora

Beginnerpackagesrhelamazon-linux

dnf is the package manager on Amazon Linux 2023, RHEL 8+, Rocky, Alma and Fedora. It reads repository metadata, solves dependencies, downloads RPMs, checks their signatures and installs them through rpm in one transaction you can later inspect and undo.

Syntaxdnf [OPTIONS] install | remove | upgrade | check-update | search | info | provides | list | history | repolist [ARGS]...

Watch it run

A new EC2 instance on Amazon Linux 2023 needs nginx. Install it and read the transaction before saying yes.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
sudo dnf install nginx

dnf refreshes metadata if it has expired, solves dependencies and prints the transaction. Unlike apt, the default answer is N: just pressing Enter cancels.

Anatomy of a command

$
commandsudo

Installing writes the RPM database and system files, so it needs root. search, info and list work without it.

How it works

dnf reads the repo definitions in /etc/yum.repos.d/*.repo, downloads each repo's repomd.xml and the primary, filelists and other metadata it points to, and caches them in /var/cache/dnf. The metadata expires (metadata_expire), so dnf refreshes it on its own and prints 'Last metadata expiration check'. libsolv, a SAT solver, turns your request plus the installed rpmdb into a transaction: installs, upgrades, removals and weak dependencies. dnf downloads the RPMs, checks their GPG signatures against keys imported from gpgkey=, then hands the transaction to librpm. rpm runs a test transaction (file conflicts, disk space) before running scriptlets and writing files and the rpmdb in /var/lib/rpm. Each transaction is recorded in the history database under /var/lib/dnf, which is what dnf history undo replays in reverse. On Amazon Linux 2023 the repos are locked to a release version, so dnf upgrade only moves within it.

Options you'll actually use

install PKG|FILE.rpmInstall packages or a local RPM, resolving dependencies from repos
remove PKGRemove packages plus unused dependencies (clean_requirements_on_remove)
upgrade [PKG]Upgrade everything, or the named packages
check-updateList available updates; exit code 100 means updates exist
search WORDSearch package names and summaries
info PKGVersion, size, repo, license and description
provides PATHWhich package ships a file or command (*/bin/dig)
list installed|availableList packages, optionally filtered by a glob
history / history undo NShow past transactions / reverse one
repolistShow enabled repositories
-yAssume yes
--securityLimit upgrade/check-update to security advisories
clean all / makecacheDrop cached metadata / download it again

Common mistakes

Pressing Enter at 'Is this ok [y/N]'

The default is No, so the transaction is cancelled ('Operation aborted.').

Type y, or use -y in automation
if dnf check-update; then echo up to date; fi

check-update exits 100 when updates exist, so the test treats 'updates pending' and real errors the same way.

dnf check-update -q; rc=$?; [ $rc -eq 100 ] && echo updates pending
Expecting the service to run after dnf install nginx

RPM packages don't start services on install; the unit is installed but inactive and disabled.

sudo systemctl enable --now nginx
Adding EPEL to Amazon Linux 2023 to get a missing package

AL2023 isn't built against EPEL's RHEL ABI; mixing repos can pull incompatible libraries.

Check dnf provides, use the vendor's AL2023 repo, or run the tool in a container

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    The sandbox is Ubuntu (no dnf). Write the dnf command that installs nginx without weak dependencies and without a prompt.

  2. 2

    Write a shell snippet that runs dnf check-update and prints 'patched', 'updates pending' or 'error'.

  3. 3

    On Ubuntu, the equivalent of 'dnf provides */bin/ss' for an installed file is dpkg -S. Find which package owns /usr/bin/ss in the sandbox.

  4. 4

    Read this and explain it: 'Error: Unable to find a match: ngnix'. What two things do you check?

Related commands

yumThe classic RPM package manager (and what it is today)rpmQuery, verify and install RPM packages directlyaptInstall, upgrade and remove packages on Debian and UbuntusystemctlStart, stop, enable and inspect systemd services
PreviousaptNextyum