How To Install Rpm In Linux

How To Install Rpm In Linux

Reading time1 min
#Linux#OpenSource#Technology#RPM#PackageManagement#Sysadmin

Mastering RPM Installation on Linux: Step-by-Step with Real-World Nuance

Installing RPM packages by hand is a core requirement for administrators working with Red Hat-based distributions—RHEL (8.x, 9.x), CentOS (7.x, 8 Stream), Fedora, and openSUSE tumbleweed/leap. This guide proceeds from version checks to dependency pitfalls, reflecting operational scenarios often missed in documentation.


Package Format: Practical Context

An RPM package (*.rpm) encapsulates binaries, configuration templates, postinstall macros, triggers, and dependency lists. Unlike modern containerized deployments or universal package managers (snap, flatpak), RPM’s dependency management is explicit—mistakes in sequence or source cause failures.

When Manual Installation Arises

  • Controlled environments: Air-gapped systems, compliance-driven upgrades.
  • Custom modules: Vendor builds or homegrown software outside primary repos.
  • Regression testing: Verifying behavior for specific versions.

# Has nginx been installed?
rpm -q nginx

If present, reports version (e.g., nginx-1.20.1-10.el8.x86_64). Otherwise, a silent “not installed”—handy in scripts.


Installing: Direct RPM

Sometimes, rpm -ivh is the only option because software arrives on USB or via restricted channels.

sudo rpm -ivh nginx-1.20.1-10.el8.x86_64.rpm
# -i: install, -v: verbose, -h: hash progress (okay for interactive shells)

Critical limitation: rpm itself performs no dependency resolution. Missing libraries or pre/post script failures halt the process.

Typical error:

error: Failed dependencies:
    libpcre.so.1()(64bit) is needed by nginx-1.20.1-10.el8.x86_64

In tightly controlled NOC or “golden image” builds, you verify the dependency chain up front (see rpm -qpR file.rpm).


Practical Installation with Dependency Resolution

For real environments, system repos enable easier management. Use dnf (RHEL 8+, Fedora 30+) or yum (RHEL/CentOS 7.x).

sudo dnf install ./nginx-1.20.1-10.el8.x86_64.rpm

Note: The ./ prefix is non-negotiable. Without it, dnf assumes the name is from a remote repo, not a local file.

Side note: yum’s localinstall is deprecated; use yum install ./package.rpm instead, but expect legacy docs to lag.

Alternative: Use dnf’s --nogpgcheck option for unsigned packages (trusted sources only).


Upgrades and Rollbacks

To upgrade in place, preserving configurations where possible:

sudo rpm -Uvh nginx-1.22.1-6.el8.x86_64.rpm

Or enforce dependency checks and proper replacement sequencing:

sudo dnf upgrade ./nginx-1.22.1-6.el8.x86_64.rpm

Gotcha: Downgrading is possible (--oldpackage) but rarely supported by vendors—config migrations may break.


Post-Installation Validation

Confirm installation and enumerate deployed files:

rpm -ql nginx

Validate package integrity (e.g., after suspected tampering or NFS issues):

rpm -V nginx

A silent return is good; listed discrepancies (denoted by “5” for MD5 sum failures) require manual evaluation.


Uninstallation and Residue

Standard removal:

sudo rpm -e nginx

With dnf or yum:

sudo dnf remove nginx

Detail: rpm -e won’t refuse to remove critical system packages (unlike APT), so double-check dependencies with rpm -q --whatrequires nginx.


Exploration and Troubleshooting

Query metadata:

rpm -qi nginx                    # Installed package info
rpm -qpi ./nginx*.rpm            # Inspect local file, no install required

Search all installed matching “nginx”:

rpm -qa | grep nginx

Dependency chain:

rpm -qR nginx

Rebuild a stuck database (known issue after power loss or abrupt kill):

sudo rm -f /var/lib/rpm/__db.*
sudo rpm --rebuilddb

Note: This does not fix deeper corruption caused by disk errors.


Quick Reference Table

OperationCommand Example
Query installedrpm -q nginx
Direct installrpm -ivh nginx-1.20.1-10.el8.x86_64.rpm
Install w/ depsdnf install ./nginx-1.20.1-10.el8.x86_64.rpm
Upgradednf upgrade ./nginx-1.22.1-6.el8.x86_64.rpm
List filesrpm -ql nginx
Removednf remove nginx
Inspect local rpmrpm -qpi ./nginx*.rpm

Nuanced Practices From the Field

  • In air-gapped deployments, assemble all required .rpm files (see dnf repoquery --requires) and use a custom local repo or the createrepo utility.
  • Avoid rpm -–force except when explicitly directed—can mask underlying filesystem divergence or configuration drift.
  • Some application vendors distribute “metapackages” that only pull in dependencies, so test in a staging environment before rolling into production.

Not perfect, but functional: RPM’s process lacks the atomic rollback features of transaction-based managers (e.g., Nix or Zypper), so snapshot or backup critical systems prior to mass operations. As always, confirm that your install base matches what your monitoring tells you: configuration drift here is all too common.

For advanced diagnostics, or to automate deployments, consider embedding these steps within an Ansible playbook or a CI/CD pipeline—systemd services and postinstall triggers tend not to play nicely with manual overrides.


For further detail—or edge cases not covered here—consult the rpm(8), dnf(8), and distribution-specific release notes.