dnfManage packages on Amazon Linux 2023, RHEL and Fedora
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.
dnf [OPTIONS] install | remove | upgrade | check-update | search | info | provides | list | history | repolist [ARGS]...A new EC2 instance on Amazon Linux 2023 needs nginx. Install it and read the transaction before saying yes.
sudoInstalling writes the RPM database and system files, so it needs root. search, info and list work without it.
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.
install PKG|FILE.rpmInstall packages or a local RPM, resolving dependencies from reposremove PKGRemove packages plus unused dependencies (clean_requirements_on_remove)upgrade [PKG]Upgrade everything, or the named packagescheck-updateList available updates; exit code 100 means updates existsearch WORDSearch package names and summariesinfo PKGVersion, size, repo, license and descriptionprovides PATHWhich package ships a file or command (*/bin/dig)list installed|availableList packages, optionally filtered by a globhistory / history undo NShow past transactions / reverse onerepolistShow enabled repositories-yAssume yes--securityLimit upgrade/check-update to security advisoriesclean all / makecacheDrop cached metadata / download it againPressing Enter at 'Is this ok [y/N]'The default is No, so the transaction is cancelled ('Operation aborted.').
Type y, or use -y in automationif dnf check-update; then echo up to date; ficheck-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 pendingExpecting the service to run after dnf install nginxRPM packages don't start services on install; the unit is installed but inactive and disabled.
sudo systemctl enable --now nginxAdding EPEL to Amazon Linux 2023 to get a missing packageAL2023 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 containerTry these on a Linux machine of your own. Each task has a hint and a solution.
The sandbox is Ubuntu (no dnf). Write the dnf command that installs nginx without weak dependencies and without a prompt.
Write a shell snippet that runs dnf check-update and prints 'patched', 'updates pending' or 'error'.
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.
Read this and explain it: 'Error: Unable to find a match: ngnix'. What two things do you check?
dnfManage packages on Amazon Linux 2023, RHEL and Fedora
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.
dnf [OPTIONS] install | remove | upgrade | check-update | search | info | provides | list | history | repolist [ARGS]...A new EC2 instance on Amazon Linux 2023 needs nginx. Install it and read the transaction before saying yes.
sudoInstalling writes the RPM database and system files, so it needs root. search, info and list work without it.
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.
install PKG|FILE.rpmInstall packages or a local RPM, resolving dependencies from reposremove PKGRemove packages plus unused dependencies (clean_requirements_on_remove)upgrade [PKG]Upgrade everything, or the named packagescheck-updateList available updates; exit code 100 means updates existsearch WORDSearch package names and summariesinfo PKGVersion, size, repo, license and descriptionprovides PATHWhich package ships a file or command (*/bin/dig)list installed|availableList packages, optionally filtered by a globhistory / history undo NShow past transactions / reverse onerepolistShow enabled repositories-yAssume yes--securityLimit upgrade/check-update to security advisoriesclean all / makecacheDrop cached metadata / download it againPressing Enter at 'Is this ok [y/N]'The default is No, so the transaction is cancelled ('Operation aborted.').
Type y, or use -y in automationif dnf check-update; then echo up to date; ficheck-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 pendingExpecting the service to run after dnf install nginxRPM packages don't start services on install; the unit is installed but inactive and disabled.
sudo systemctl enable --now nginxAdding EPEL to Amazon Linux 2023 to get a missing packageAL2023 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 containerTry these on a Linux machine of your own. Each task has a hint and a solution.
The sandbox is Ubuntu (no dnf). Write the dnf command that installs nginx without weak dependencies and without a prompt.
Write a shell snippet that runs dnf check-update and prints 'patched', 'updates pending' or 'error'.
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.
Read this and explain it: 'Error: Unable to find a match: ngnix'. What two things do you check?