How to Install an RPM Package on Linux

How to Install an RPM Package on Linux

Reading time1 min
#Linux#RPM#PackageManagement#Dnf#Fedora#RHEL

How to Install an RPM Package on Linux

An .rpm file is a software package for Fedora, Red Hat Enterprise Linux and its rebuilds (Rocky Linux, AlmaLinux, CentOS Stream), Amazon Linux, openSUSE and SUSE Linux Enterprise. It holds the program's files, metadata (name, version, architecture, dependencies) and optional scripts that run during installation.

An RPM is not something you execute. You install it with the package manager, then run the program it installed.

If the software is in your distribution's repositories, install it from there. A downloaded RPM makes sense when the vendor only ships it that way.

Install with dnf (Fedora, RHEL 8+, Rocky, Alma, Amazon Linux 2023)

sudo dnf install ./my-app-1.2.3-1.x86_64.rpm

dnf reads the package's dependencies and pulls the missing ones from your enabled repositories. The transaction is recorded, so dnf history shows it and dnf history undo can roll it back.

dnf also accepts a URL, which is how packages such as epel-release are often installed:

sudo dnf install https://example.com/downloads/my-app-1.2.3-1.x86_64.rpm

On RHEL 8 and later yum is just a link to dnf, so sudo yum install ./file.rpm does the same thing. Fedora 41 and later use dnf5, with the same commands for everything shown here.

If dnf reports "nothing provides libfoo.so.1", find which package and repository has it:

dnf provides '*/libfoo.so.1'

On RHEL-family systems the answer is often EPEL or the CodeReady Builder (CRB) repository, which you have to enable first.

Older systems such as CentOS 7, RHEL 7 and Amazon Linux 2 use sudo yum install ./file.rpm. All three are past the end of standard support, so plan a move to a current release.

Install with zypper (openSUSE, SLES)

sudo zypper install ./my-app-1.2.3-1.x86_64.rpm

zypper resolves dependencies the same way. For an unsigned package it asks for confirmation; --allow-unsigned-rpm skips the question, so only use it for packages you built yourself.

Install with rpm

rpm is the low-level tool. It installs exactly the file you give it and never downloads dependencies.

sudo rpm -ivh my-app-1.2.3-1.x86_64.rpm    # install (-v verbose, -h progress bar)
sudo rpm -Uvh my-app-1.2.4-1.x86_64.rpm    # upgrade, or install if not present
sudo rpm -Fvh my-app-1.2.4-1.x86_64.rpm    # upgrade only if an older version is installed

If something is missing you get "error: Failed dependencies: libfoo.so.1()(64bit) is needed by my-app". Install those with dnf, or simply use dnf for the whole thing. Avoid --nodeps and --force: the package ends up installed without what it needs, and the next dnf transaction complains about a broken dependency tree.

One special case: install kernel RPMs with -i, never -U, so the running kernel stays installed as a fallback.

Inspect and verify before installing

Packages install as root and their scriptlets run as root, so look before you install:

rpm -qpi my-app.rpm            # name, version, vendor, build host, signature
rpm -qpl my-app.rpm            # files it will install
rpm -qpR my-app.rpm            # what it requires
rpm -qp --scripts my-app.rpm   # pre/post install scripts
rpm -K my-app.rpm              # check digests and signature

The -p flag means "query this package file" instead of the installed package database.

rpm -K should report digests signatures OK. If it says SIGNATURES NOT OK or mentions NOKEY, the vendor's signing key is not imported yet. Get the key from the vendor's site over HTTPS and import it:

sudo rpm --import https://example.com/keys/RPM-GPG-KEY-my-app
rpm -K my-app.rpm

Do this check yourself: dnf does not always verify the signature of a local file (on dnf 4 the localpkg_gpgcheck option is off by default).

Find and run the installed program

rpm -q my-app                  # installed? which version
rpm -ql my-app | grep bin/     # executables it installed
rpm -qf /usr/bin/my-app        # which package owns a file
rpm -V my-app                  # compare installed files with the package metadata

rpm -V prints nothing when every file matches. Lines like S.5....T. c /etc/my-app.conf mean the size, checksum and timestamp differ, which is normal for config files you edited.

Upgrade and remove

sudo dnf upgrade ./my-app-1.2.4-1.x86_64.rpm
sudo dnf remove my-app

dnf remove also removes dependencies that were pulled in only for this package. sudo rpm -e my-app removes just the package and refuses if something else depends on it.

A hand-installed RPM does not update itself. Some vendor packages add a repository file to /etc/yum.repos.d/; if yours did, sudo dnf upgrade keeps it current.

Extract an RPM without installing it

mkdir my-app-files && cd my-app-files
rpm2cpio ../my-app-1.2.3-1.x86_64.rpm | cpio -idmv

This creates ./usr, ./etc and so on in the current directory. It works on any distribution with rpm2cpio and cpio installed, including Ubuntu (sudo apt install rpm2cpio cpio).

An RPM on Ubuntu or Debian

Ubuntu and Debian use dpkg and apt, which know nothing about RPM. Go through these options in order:

  1. Look for a native package. Check the vendor's site for a .deb, an apt repository, a Snap, a Flatpak or a plain tarball. One of them usually exists.

  2. Extract it. If the RPM contains a single self-contained binary, extract it with rpm2cpio as shown above and copy the binary to /usr/local/bin.

  3. Convert it with alien.

    sudo apt install alien
    sudo alien --to-deb --scripts my-app-1.2.3-1.x86_64.rpm
    ls *.deb
    sudo apt install ./my-app_1.2.3-2_amd64.deb
    

    alien increases the release number by one unless you pass -k, so check the output name. Dependencies are not translated (Fedora and Debian name libraries differently) and scripts written for RHEL may fail. Fine for simple packages, risky for anything with services, drivers or kernel modules.

  4. Run it in a container of the distribution it was built for:

    docker run --rm -it -v "$PWD":/pkg fedora:latest \
      bash -c 'dnf install -y /pkg/my-app-1.2.3-1.x86_64.rpm && my-app --version'
    

Do not install the rpm tool on Ubuntu and run rpm -i. It keeps a separate database that dpkg ignores, and dependencies cannot be satisfied. Older Debian and Ubuntu builds only print a warning pointing you to alien, and current ones (Debian 13, Ubuntu 26.04) do not even warn.

Quick reference

sudo dnf install ./file.rpm         # install with dependencies (Fedora, RHEL 8+, AL2023)
sudo zypper install ./file.rpm      # openSUSE, SLES
sudo rpm -ivh file.rpm              # low-level install, no dependency resolution
sudo rpm -Uvh file.rpm              # upgrade or install
rpm -qpi file.rpm                   # package info
rpm -qpl file.rpm                   # list files
rpm -K file.rpm                     # verify signature
rpm -ql package-name                # files of an installed package
sudo dnf remove package-name        # uninstall
rpm2cpio file.rpm | cpio -idmv      # extract without installing
sudo alien --to-deb --scripts file.rpm   # convert for Ubuntu/Debian (last resort)