TT Lab
Get started
Learn Learning paths Courses

RHEL-Family Administration

dnf in Practice

Continue in TT Lab

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

  1. 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.
  2. Query the information of the tree package and write only the version string on one line in /root/rh/tree-version.txt.
  3. 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.
  4. Find the package that provides /usr/bin/tree and write only the package name on one line in /root/rh/provides.txt.
  5. Save the list of dnf transactions to /root/rh/history.txt. There must be at least one transaction.
  6. 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.
  7. 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.
  8. 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)

Notes

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.