How To Install An Rpm

How To Install An Rpm

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

Mastering RPM Installation: Practical Guide for Red Hat-Based Systems

Deploying software at scale on RHEL, CentOS, or Fedora isn’t about clicking “Install.” Controlled RPM package management is fundamental for system reproducibility and auditability—especially on servers or in regulated production environments.


RPM Packages: Anatomy and Use Cases

An .rpm file is more than a package; it’s a bundle containing application binaries, configuration files, service definitions, and install/uninstall scripts. For minimal systems, staging environments, or air-gapped datacenters, RPMs are the only practical option.

Direct RPM use provides:

  • Version pinning without repo fluctuations
  • Manual dependency management for precise rollout sequencing
  • Full visibility into post/pre install scripts (easily inspected with rpm -qpi --scripts package.rpm)

Baseline: System Preparation

Production change management begins with cache sync:

sudo dnf makecache
# Legacy systems (pre-Fedora 22, RHEL/CentOS 7 or earlier):
sudo yum makecache

Check your tools:

which rpm
which dnf    # Or yum, as appropriate
rpm --version    # Confirm at least 4.11 for reliable scriptlet execution

Firewalls, SELinux contexts, or custom repo configs can block RPM operations—a recurring source of “mystery” failures.


The RPM Command: Controlled, But Unforgiving

RPM itself (rpm -ivh package.rpm) won’t resolve dependencies. This is by design.

Typical install:

sudo rpm -ivh nginx-1.22.1-9.el9.x86_64.rpm
# Output:
# error: Failed dependencies:
#   libpcre.so.1()(64bit) is needed by nginx-1.22.1-9.el9.x86_64

At this point, your RPM is not installed. Dependency trees can be more complex than the example above.

Advanced: Dependency Checks Without Install

rpm -qpR nginx-1.22.1-9.el9.x86_64.rpm
# Lists ALL required libraries and version constraints

Dependency Management: Manual and Automatic

Resolving failed dependencies is routine:

sudo dnf provides '*/libpcre.so.1'
# dnf (or yum) gives the package that provides this .so
sudo dnf install pcre
# Or yum, per OS

No repo? Handling builds from source, or deploying to isolated networks? Download missing packages on a networked staging box, then transfer via scp or rsync (and scripts like repotrack can automate this for complex chains).

Gotcha: Package signatures occasionally fail (error: package.rpm: Header V4 RSA/SHA256 Signature, key ID ...: NOKEY). Import the GPG key using rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release (or relevant key file).


Local Installation With Dependency Resolution

On modern systems, avoid manual juggling:

sudo dnf install ./example-app-1.2.3.rpm
# Or legacy:
sudo yum localinstall example-app-1.2.3.rpm

This instructs the package manager to resolve and install dependencies, pulling from enabled repos. For offline, set up a local repo via createrepo and point your system’s .repo file accordingly.


Upgrading or Downgrading RPMs

Upgrading, replacing, or forcibly downgrading packages:

sudo rpm -Uvh example-app-2.0.0.rpm
# -U: upgrade or install if missing
# Downgrade? Add --oldpackage flag:
sudo rpm -Uvh --oldpackage example-app-1.2.3.rpm

Mixing package major versions? This isn’t always safe—pay attention to config file migration. Always back up /etc/example-app/, or use snapshotting for full risk mitigation.


Clean Package Removal

Clean uninstalls:

rpm -e example-app

Don’t append .rpm—uninstall requires the package “name,” not file.

Audit before removal:

rpm -qa | grep example-app

Note: Orphaned config files in /etc or /var are not always removed. Check, then purge manually if needed.


Inspection Without Installation

Dissect an RPM before deployment:

rpm -qpi ./example-app-1.2.3.rpm      # Detailed metadata
rpm -qpl ./example-app-1.2.3.rpm      # File manifest
rpm -qp --scripts ./example-app-1.2.3.rpm   # Scriptlets (critical for compliance)

Validation, Integrity, and Forced Installs

Integrity check, post-install:

rpm -V example-app
# Outputs file-level differences: M (mode), 5 (md5), S (size), etc. No output means exact match.

Forcing Installs: Only for tested disaster-recovery contexts.

sudo rpm --force -ivh example-app-1.2.3.rpm

Warning: This skips all conflict checks and can render systems unbootable or inconsistent. Audit dependencies and planned changes first.


Reference Table

TaskCommand ExampleNote
Direct installsudo rpm -ivh pkg.rpmNo dependency resolution
Install w/ depssudo dnf install ./pkg.rpmRecommended (auto-resolves dependencies)
Upgradesudo rpm -Uvh pkg.rpmUse --oldpackage to downgrade
Removesudo rpm -e pkgRemoves by name
Inspect metadatarpm -qpi pkg.rpmNo install required
List package filesrpm -qpl pkg.rpmUseful before extracting
Verify post-installrpm -V pkgFile integrity
Find package for filednf provides '*/libXYZ.so.1'Essential for dependency hunts

Practical Example: Installing a Third-Party RPM

  1. Download custom-agent-5.6-1.x86_64.rpm from vendor portal.

  2. Check integrity:

    sha256sum custom-agent-5.6-1.x86_64.rpm
    rpm -qpi custom-agent-5.6-1.x86_64.rpm
    
  3. Attempt install with dependency resolution:

    sudo dnf install ./custom-agent-5.6-1.x86_64.rpm
    
  4. If the install fails due to missing dependencies, use dnf provides, fetch those RPMs manually in restricted environments, and repeat.


Non-Obvious Tip: Staging and Compliance

Scripted installs for air-gapped environments? Bundle all RPMs—including dependencies—using repotrack, then transfer and create a local repo:

repotrack -a x86_64 custom-agent
createrepo /path/to/rpms/
# Update /etc/yum.repos.d/local.repo accordingly

This method reduces manual errors and allows completely repeatable deployment pipelines.


Known Issues

  • Some RPMs (especially vendor builds) have broken dependency specs. Always verify with rpm -qpR.
  • SELinux enforcement can silently block post-install steps. Review audit.log if expected configuration isn’t applied.
  • Symlinked files in /usr may not be cleanly removed on uninstall; audit with find post-removal.

Closing Note

The value in mastering RPM at the CLI level comes during outages, migrations, and audits—where GUI abstractions offer no recourse. Familiarity with the raw tooling means shorter incident bridges and more predictable change management. For complex estates, centralize packages in a vetted repository and script your install logic.

If you run into non-resolvable conflicts—don’t just force. Investigate: check rpm -Vp, scrutinize hooks, and weigh rollback plans. Deployment is only the start.