How To Run Rpm File In Linux

How To Run Rpm File In Linux

Reading time1 min
#Linux#Software#OpenSource#RPM#PackageManagement#Fedora

Mastering RPM Installation on Linux: Efficiency and Control

Manually installing RPM packages arises when a vendor provides only an .rpm, or upstream repositories lag behind required versions. While dnf (or yum) automates most tasks, direct use of RPM utilities provides finer control and a better understanding of what’s happening under the hood. But missteps—especially dependency oversights—often result in partially installed or broken packages.

Consider a scenario: deploying a third-party monitoring agent on RHEL 9. The vendor only provides an RPM, and your environment doesn’t allow external repositories. Correct handling is critical to avoid contaminating your package state.


RPM Files: Structure and Usage Context

RPM (Red Hat Package Manager) files bundle application binaries, config files, install/uninstall scripts, and metadata. The .rpm suffix surfaces on distributions like CentOS, RHEL, Fedora, and openSUSE.

Techs reach for raw RPMs when:

  • Software isn’t available or up-to-date in official repos.
  • Need arises for explicit version locking (e.g., security compliance).
  • Troubleshooting cyclic or missing package dependencies.

System Prep — Dependencies, Tools, and Cache State

Always update repositories and clear old caches first—stale package data can cause conflicts during manual installs.

sudo dnf clean all                  # Clean repository metadata and cache
sudo dnf update                     # For Fedora, RHEL 8+/CentOS 8+
# or
sudo yum update                     # For CentOS/RHEL 7 and older

Rare edge case: if minimal container images omit the rpm tooling,

sudo dnf install rpm

For most mainstream environments, rpm, yum, and dnf are present by default.


Installing an RPM: Direct vs. Dependency-Resolving Methods

Methods diverge here:

1. Raw rpm (rpm -i/-U): No Automatic Dependency Resolution

Install:

sudo rpm -ivh /path/to/package.rpm
  • -i: install (use -U for upgrade/replace)
  • -v: verbose
  • -h: print hash progress

Example:

sudo rpm -ivh telegraf-1.25.0-1.x86_64.rpm

An unmet dependency halts install and returns:

error: Failed dependencies:
    libltdl.so.7()(64bit) is needed by telegraf-1.25.0-1.x86_64

Critical: no rollback occurs if the pre-install script runs but files partially lay down—handle with care.

2. High-Level (dnf install ./file.rpm or yum localinstall file.rpm)

These commands resolve dependencies against enabled repositories.

sudo dnf install ./nginx-1.24.0-1.el9.x86_64.rpm
# or
sudo yum localinstall ./nginx-1.24.0-1.el7.x86_64.rpm

Add ./ to force install from the local file; omitting it can cause “package not found” errors. If dependencies are unmet in repos, the install reports specifics and fails cleanly.

Summary Table:

CommandDependency HandlingUse Case
rpm -ivh X.rpmNoneUpgrade/downgrade in strict, repo-isolated environments
dnf install ./X.rpmYes (resolves)All normal cases
yum localinstall X.rpmYes (legacy systems)CentOS/RHEL 7 and below

Upgrading and Downgrading RPMs

For upgrades:

sudo rpm -Uvh ./X.rpm        # replaces old, keeps modified configs
sudo dnf upgrade ./X.rpm     # alternative, resolves new deps if needed

Downgrade is possible but not well-supported by dnf/yum; use rpm -Uvh --oldpackage if forced.

Real-world caveat: Config files with local changes won’t be overwritten but .rpmnew or .rpmsave files may appear in /etc. Audit for these after the upgrade.


Inspecting, Querying, and Verifying RPMs

Before trusting any external RPM, parse its info:

rpm -qpi ./X.rpm         # Print package metadata (name/version/etc)
rpm -qpl ./X.rpm         # List all files it will install
rpm -qd ./X.rpm          # Show included documentation

Validate installation:

rpm -q X                 # Is package installed?
rpm -V X                 # Verify installed files (checksum, size, mod date)

Known issue: rpm -V will report mismatches on deliberately edited config files; investigate changes before assuming corruption.


Removing or Forcing Cleanups

Uninstall:

sudo dnf remove nginx         # preferred — resolves package relationships
sudo rpm -e nginx             # direct, can leave orphan dependencies

If you mistakenly install RPMs with unmet dependencies:

sudo dnf distro-sync          # Re-syncs packages to repo versions
sudo dnf repoquery --unneeded # Lists orphaned RPMs
# Less known: dnf install -f is not standard; use distro-sync or explicit reinstall

Troubleshooting: Non-Obvious Pitfalls

  • Parallel installs: Some packages permit multiple versions; others use “conflicts” flags—always inspect with rpm -qpl before install.
  • SELinux contexts: Manual RPM installs outside normal paths (e.g., /opt) may not get correct SELinux labels. Fix with:
    sudo restorecon -Rv /opt/yourapp
    
  • Systemd units: Check whether the new package registers/overrides systemd units with:
    rpm -qpl ./X.rpm | grep '\.service$'
    

At a Glance: Workflow for Custom RPM Installs

1. Inspect RPM for contents and dependencies
2. Always use `dnf install ./package.rpm` (fallback to `rpm -i` _only_ if required)
3. Verify install integrity with `rpm -V`
4. Post-install: check for `.rpmnew`, `.rpmsave` files and audit `/var/log/messages` for anomalies

ASCII: Typical lifecycle

[ inspect ] -> [ install ] -> [ check integrity ] -> [ cleanup/rollback if needed ]

Closing Observations

Direct RPM handling unlocks software flexibility on RPM-based Linux distributions—at the cost of higher risk. Always prefer high-level tools first for dependency safety. Manual rpm installs are valid for controlled, offline, or isolated patching workflows, but require extra caution around dependencies and system integrity.

If you encounter persistent dependency loops or need to craft custom RPMs, consider rebuilding spec files with rpmbuild—beyond the scope of this guide but often overlooked in devops environments.


Practical tip: After installing complex software (e.g., monitoring agents or custom kernels), snapshot your system or produce an RPM manifest for rollback traceability. This rarely appears in official docs, but saves significant time on recovery.