Linux Command Reference ยท Packages and Services
Linux rpm command
Reference for the Linux rpm command: install, upgrade and remove .rpm files, query installed packages and their files, verify integrity and check signatures.
rpm is the low-level package manager of Red Hat, Fedora, SUSE and related distributions. It works with individual .rpm files and a local database of installed packages (in /var/lib/rpm). Like dpkg on Debian, it installs the files you give it, checks that dependencies are present, and does not download anything. For normal work, dnf (or zypper on SUSE) drives rpm for you.
Where rpm really shines is querying. It can tell you which package owns a file, what a package contains, what scripts it runs, and whether an installed file has been modified since installation.
rpm -q PACKAGE rpm -qf /path/to/file sudo rpm -ivh package.rpm
Try it
The sandbox is Debian-based and has no rpm, so this block is read-only:
$ rpm -q bash bash-5.2.26-3.fc40.x86_64 $ rpm -qf /usr/bin/ls coreutils-9.4-6.fc40.x86_64 $ rpm -ql tree | head -3 /usr/bin/tree /usr/share/doc/tree/README.md /usr/share/man/man1/tree.1.gz $ rpm -V coreutils # no output: every file is unchanged $ rpm -qa --last | head -2 # the most recently installed packages
An RPM version string has an optional epoch, a version and a release. This block pulls apart the "name-version-release.arch" format that rpm -q prints:
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
rpm -i|-U|-F [OPTIONS] FILE.rpm... # install, upgrade, freshen rpm -e [OPTIONS] PACKAGE... # erase (remove) rpm -q [SELECT] [QUERY-OPTIONS] # query rpm -V [SELECT] # verify rpm -K FILE.rpm # check signature
| Option | Description |
|---|---|
-i, --install |
Install a new package (fails if one is already installed). |
-U, --upgrade |
Install, or upgrade and remove the older version. This is the usual choice. |
-F, --freshen |
Upgrade only packages that are already installed. |
-e, --erase |
Remove an installed package. |
-v, -h |
Verbose; print hash marks as progress (-ivh, -Uvh). |
--test |
Check what would happen without changing anything. |
--nodeps, --force |
Skip dependency checks or force an action. Dangerous. |
| Query option | Description |
|---|---|
-q NAME |
Is it installed? Prints the full name or "package NAME is not installed". |
-qa |
All installed packages (-qa 'kernel*' filters). |
-qi NAME |
Information: version, vendor, build date, summary. |
-ql NAME |
List the files in a package. |
-qc NAME, -qd NAME |
Only configuration files, or only documentation. |
-qf PATH |
Which package owns this file. |
-qp FILE.rpm |
Query an uninstalled package file (combine with -i, -l, -R). |
-qR NAME |
What the package requires. |
--whatprovides CAP |
Which installed package provides a capability. |
--scripts |
Show install and removal scriptlets. |
--qf FORMAT |
Custom output, for example --qf '%{NAME} %{VERSION}\n'. |
Returns: 0 on success; a query for a missing package, a failed verification or a failed installation returns non-zero.
Usage notes
- Use
-Urather than-iunless you intentionally want two versions (such as multiple kernels, which are installed side by side). - Dependencies are not downloaded. If
rpmcomplains about "Failed dependencies", usesudo dnf install ./file.rpminstead, which resolves them. - Verify files.
rpm -V PKGprints one line per changed file, with flags such asS(size),5(checksum),T(time) andc(config file). Changes to config files are normal; changes to binaries deserve a look. - Check authenticity.
rpm -K file.rpmverifies digests and signatures; import the vendor key first withsudo rpm --import KEYFILE. - Extract without installing:
rpm2cpio file.rpm | cpio -idmvunpacks the payload into the current directory. - Custom output:
rpm -qa --qf '%{NAME}\t%{SIZE}\n' | sort -k2 -n -r | headshows the biggest packages. - Database trouble. If
rpmreports a locked or corrupted database,sudo rpm --rebuilddbrebuilds the indexes. - Epoch. The full version is
epoch:version-release; a package with a higher epoch always wins, even with a lower version number.
Related
dnfandyum,dpkg,aptandapt-get,cpio- Lessons: Packages and Services, Archives