Rocky Linux 10 Tutorial / Find, install and inspect packages with DNF and RPM

When finding and installing programs on Rocky Linux 10, use DNF to handle repositories and dependencies together, and use RPM query commands to check information about installed packages or file ownership relationships. In this article, we learn the roles of the two tools and how to check results by searching, installing, running, and removing tree.

Understand the relationships between packages, repositories, and dependencies

A package is a unit that manages not only executable files but also manuals, licenses, installation information, etc. For example, the tree package includes an executable that displays directories in a tree structure along with manuals. A repository provides the packages to be installed and their list and version information as a source.

Other libraries may be required for the program to run. This relationship is a dependency. DNF (Dandified YUM) compares the current system with active repository information to create the necessary installation and modification plans. RPM (RPM Package Manager) handles packages and the installation database, and in this course, it is mainly used for local queries. While it is possible to install directly with RPM, the general installation flow that finds and resolves dependent packages from remote repositories is handled by DNF.

Guide to DNF on Rocky Linux explains package management commands. Before mixing DNF5 examples from other distributions as they are, check the version. The recorded source lab used a Rocky Linux 10.2 minimal guest, DNF 4.20.0 and RPM 4.19.1.1. Its commands ran inside the guest shell, not on the Windows host.

cat /etc/rocky-release
dnf --version
rpm --version
dnf repolist --enabled

In the practice VM, baseos, appstream, extras were active. For this example, no additional repositories are installed. Installation and removal require sudo privileges of a regular administrator account, and repository queries may require network and name resolution.

Distinguish between name lookups and package searches that provide files

First, check whether it is currently installed. If it is not installed, it will be displayed like package tree is not installed, and the exit status may not be 0. You need to determine whether this result is the expected state before installation.

rpm -q tree
dnf search tree
dnf info tree

search searches for names and summaries related to a keyword, so multiple packages containing the word 'tree' may appear together. On the other hand, info tree is used to examine the description, version, architecture, and repository of a specified package in detail. Seeing the name in search results and it being already installed are different things.

When you only know the file path of a command, find the providing package. The file list before installation can also be looked up from repository metadata.

dnf provides /usr/bin/tree
dnf repoquery --list tree
dnf repoquery --requires --resolve tree

The results of provides in this practice were tree-2.1.0-8.el10.x86_64, the repository was baseos, and /usr/bin/tree matched. The last command checks dependencies based on the repository, and the number of packages actually added during installation depends on the libraries already installed. Determine the current version and repository from your own output.

The source lab’s initial cache-only query using dnf -C provides /usr/bin/tree failed because the file-list metadata was not cached. -C is an option to use only the cache without network updates, so in such cases, if normal repository access is possible, remove -C and check again. After fetching the required file-list metadata, the source lab successfully located the same path. Cache errors are not assumed to mean that the package does not exist.

Read the installation plan and approve it.

For the first installation, it is easier to learn the changes by skipping -y, which automatically answers yes. First, run a preview that ends with a no response.

sudo dnf --assumeno install tree

Answer no to confirmation questions with --assumeno. Metadata lookup and dependency calculations can be performed, but the installation transaction is not approved. On this VM, the following plan was checked.

Installing:
 tree  x86_64  2.1.0-8.el10  baseos  56 k

Transaction Summary
Install  1 Package
  1. Verify that the name and architecture to be installed match the intended target.
  2. Verify that the repository is from a trusted source. If you see an unexpected external repository, first investigate the cause.
  3. Read all items scheduled for additional installation, upgrade, or removal. Even if one tree is requested, dependency packages may be added in other environments.
  4. Check the download size and the space available after installation, and verify the reviewed plan again in the actual installation command.

The appearance of Operation aborted. and exit status 1 in the preview was the intended rejection result this time. Network errors and other issues can also end in a non-zero state, so do not judge normal or error based on the number alone; read the preceding message as well. Now proceed with the actual installation.

sudo dnf install tree

If the plan is the same, answer the confirmation question with y. If approval for a new signing key is required, check the full fingerprint and source of the official key before deciding. Do not attach --nogpgcheck just to eliminate a signing error. In this VM, the Rocky key verified in a previous update process was already registered, so it was installed without new key approval.

After checking DNF’s Complete! and the installation list, verify the results with separate queries and execution. If the installation was interrupted or the SSH connection was lost, first check the actual installed state with rpm -q tree and the DNF history, rather than immediately repeating the same command.

Cross-check the installed versions, files, and sources.

The following queries answer different questions each. The RPM command reference explains these query options. The source lab checked the basic queries below with RPM 4.19.1.1.

Command Questions to check
rpm -q tree What is the version and release of the currently installed tree?
rpm -qi tree What are the package details such as description, installation date, and provider?
rpm -ql tree What are the file paths registered in the installation database?
rpm -qf /usr/bin/tree Which package owns this installation file?
dnf info --installed tree What installation packages and source information does DNF record?
sudo dnf history info last Which packages were actually changed in the last DNF operation?
rpm -q tree
rpm -qi tree
rpm -ql tree
rpm -qf /usr/bin/tree
dnf info --installed tree
sudo dnf history info last

In this practice, both version lookup and file ownership lookup pointed to tree-2.1.0-8.el10.x86_64. The file list included executable files, documents, license files, and man page paths. The Repository: @System in the DNF information indicated installed system packages, and we checked the sources separately recorded in From repo: baseos and the installation transaction @baseos.

The source history does not always remain in the same form across all installation methods. When an RPM file is installed separately or migrated to another system, DNF's "From repo" may not be present. Do not determine reliability solely based on the RPM provider string or the short key ID; consider the installation path, repository settings, and the verified signature key together.

Check the actual execution with a small directory example.

The following full example creates a unique temporary directory under a general user's home and writes two files inside it. Execute them sequentially in the same Bash shell. The random suffix generated by mktemp changes each time, and administrative privileges are not required.

LabDir=$(mktemp -d "$HOME/dnf-lab.XXXXXX")
mkdir "$LabDir/docs"
printf 'package practice\n' > "$LabDir/README.txt"
printf 'local notes\n' > "$LabDir/docs/note.txt"
tree --charset=ASCII "$LabDir"

Except for the arbitrary name of the directory, the following structure should be visible. This output was actually confirmed on a Rocky Linux guest.

/home/lfstudent/dnf-lab.G8zzfH
|-- README.txt
`-- docs
    `-- note.txt

2 directories, 2 files

Distinguish between files displayed by the program and files installed by packages. The following command checks whether the README file just created by the user belongs to any RPM-owned package.

rpm -qf "$LabDir/README.txt"

This is the expected result in this case by is not owned by any package. It means the data created by the user is not registered in an RPM, and does not imply that the files are unnecessary or corrupted. After finishing this example, remove only the files you created yourself and clean up the empty directory.

rm -- "$LabDir/README.txt" "$LabDir/docs/note.txt"
rmdir -- "$LabDir/docs" "$LabDir"

If a variable has disappeared in a new shell, do not guess and execute cleanup commands. First, check the actual creation path and content. If another file is added and rmdir rejects it, check what that file is.

Check the meaning and limitations of file integrity checks.

The fact that a list of files appears does not guarantee that the current file contents match the original state. When comparing file attributes registered in the package with the current state, use uppercase -V.

rpm -V tree
printf 'verify exit=%s\n' "$?"

In the source lab, verification reported no differences and exited with status 0. If there are differences, comparison items such as size, mode, digest, and time may be displayed in front of the path. Differences caused by administrator modifications to configuration files also exist, so do not conclude malicious changes or overwrite the original file immediately just because there is output.

This check compares local RPM database information with files. It does not prove that the entire untrusted system is safe or check all user data. Checking file ownership, comparing changes, and trusting the source are separate verification processes.

Check the removal plan and clean up only the practice packages.

If tree was installed from the beginning or is in use by another task, it is not removed just because you practiced installation by following this guide. In the source lab, tree was absent before the exercise and no other workload required it after installation.

sudo dnf --assumeno remove tree

The removal plan can include packages that depend on the requested package and dependencies that are no longer needed. Compare the plan with the remove command in the official DNF reference. In the source lab, only Remove 1 Package and tree appeared. Do not approve if other important software is listed.

sudo dnf remove tree
rpm -q tree
command -v tree
sudo dnf history info last

Read the exact removal scope again, approve it, and then confirm that the package is uninstalled and the execution path is absent. The source lab recorded the removal transaction as Success, and the hash of the existing repository settings file, SSH service, and SELinux Enforcing status were also preserved. The DNF history is a reference to check the last package change and is not a backup to restore user data. If you need to keep or reinstall it, review the active repository and installation plan, then install with sudo dnf install tree.

Points to check when the query results differ from expectations

Phenomenon First things to check
There are search results, but rpm -q shows not installed It is normal for the installation candidate in the repository and the current installation status to differ. First, determine whether installation is necessary.
No match or repository metadata error Check the spelling of the name, active repository, DNS, network, and cache restrictions. If necessary, retrieve the latest information from dnf --refresh info tree.
Installed but command not found Compare the path in rpm -ql tree with command -v tree. Command names and package names are not always the same.
No owning package for rpm -qf Verify whether it is the correct path, user data, or manually installed file. Do not delete simply because ownership information is missing.
Dependency conflict or signature verification failure Record messages and change plans, and investigate combinations of source, key, and version first. Do not bypass using --nodeps or skipping signature checks.