dnf in Practice
Goal
With dnf you check the repository, install, trace a package back from a file, roll back a transaction, and pin a version.
Why it matters
The decisive difference of dnf is that every install is recorded as a transaction and can be undone. apt has no corresponding feature. This difference changes the way you operate — "install it to see, and undo it if it isn't right" becomes possible. But it fails if the previous version is not in the repository, and downgrading system packages such as the kernel or glibc is not supported.
And dnf provides is more powerful than dpkg -S. Because it digs through the repository metadata, it finds even packages that are not yet installed. In RPM the unit of a dependency is not a package name but a capability (a file path, a library soname), which is why this tool is essential.
Steps
- Create the
/root/rhdirectory and save the detailed repository list to/root/rh/repolist.txt. A baseurl pointing to/opt/localrepomust be visible. - Query the information of the
treepackage and write only the version string on one line in/root/rh/tree-version.txt. - Install
treeandnano, and write the NEVRA of each of the two packages (therpm -qoutput), one line each, in/root/rh/installed.txt. - Find the package that provides
/usr/bin/treeand write only the package name on one line in/root/rh/provides.txt. - Save the list of dnf transactions to
/root/rh/history.txt. There must be at least one transaction. - Undo the transaction that installed
nano(undo). After undoing it,nanomust not be installed, and save that state to/root/rh/after-undo.txt. - Pin the version of
tree. If thednf versionlockplugin is present, use its command; if not, write it directly in/etc/dnf/plugins/versionlock.list. Save the lock state to/root/rh/lock.txt. - Make
/root/rh/report.txtwith the following 4 lines.TREE=<tree 의 설치 버전>/NANO=<removed 또는 installed>/PROVIDER=<4번에서 찾은 패키지 이름>/LOCKED=tree(that is, the installed version of tree, removed or installed, and the package name found in step 4)
Notes
- The order is
dnf repolist -v,dnf info tree,dnf provides '*/bin/tree',dnf history,dnf history undo <ID> -y. - To check whether something is installed, use
rpm -q <패키지>(the placeholder is the package name). If it is not installed, "is not installed" comes out. - To pull only the version,
rpm -q --qf '%{VERSION}-%{RELEASE}\n' <패키지>is handy. - Common mistake 1: picking the wrong transaction ID in step 6 and undoing the wrong thing. Check first with
dnf history info <ID>. - Common mistake 2: saving the whole output of
dnf providesin step 4. You need only the name of the package.
Checking the repository
Create the /root/rh directory and save the detailed repository list to /root/rh/repolist.txt. A baseurl pointing to /opt/localrepo must be visible.
dnf repolist has a verbose output option. The local repository's baseurl must be visible.
Querying package information
Query the information of the tree package and write only the version string on one line in /root/rh/tree-version.txt.
dnf info shows the version, repository, size, and summary. Pull out only the version value.
Installing packages
Install tree and nano, and write the NEVRA of each of the two packages (the rpm -q output), one line each, in /root/rh/installed.txt.
Get into the habit of checking with rpm -q after installing. It comes out in the name-version-release.architecture format.
Tracing a package back from a file
Find the package that provides /usr/bin/tree and write only the package name on one line in /root/rh/provides.txt.
dnf provides digs through the repository metadata too, so it finds packages that are not installed as well.
Checking transactions
Save the list of dnf transactions to /root/rh/history.txt. There must be at least one transaction.
See the list with dnf history and the details with history info. The ID is a number.
Undoing a transaction
Undo the transaction that installed nano (undo). After undoing it, nano must not be installed, and save that state to /root/rh/after-undo.txt.
undo performs the opposite of the specified transaction. To proceed without confirmation, you need -y.
Pinning a version
Pin the version of tree. If the dnf versionlock plugin is present, use its command; if not, write it directly in /etc/dnf/plugins/versionlock.list. Save the lock state to /root/rh/lock.txt.
If the plugin is present, use the command; if not, you can write it directly in the configuration file.
Summary report
Make /root/rh/report.txt with the following 4 lines.
TREE=<tree 의 설치 버전> / NANO=<removed 또는 installed> / PROVIDER=<4번에서 찾은 패키지 이름> / LOCKED=tree (that is, the installed version of tree, removed or installed, and the package name found in step 4)
The values must be actual query results. Judge the state by whether it is installed.