Skip to content

How to Extract an RPM Package Without Installing It ​

Extracting files from an RPM package without installing it

Every now and then, whether you're doing day-to-day Linux ops or packaging software for delivery, you need to pull binaries, shared libraries and config files out of an RPM package — without going through yum install or rpm -ivh at all. Common reasons:

  • Grab a single executable out of a package.
  • Recover a shared library that the package ships.
  • Inspect how a package lays out its files.
  • Harvest resources from a third-party RPM to bundle into your own deliverable.
  • Audit a package's contents without touching the running system.

RPM ships a small utility called rpm2cpio, which converts a package into a CPIO stream; cpio then extracts files from that stream.

1. The Two Tools You Need ​

That's the whole toolchain — just two commands:

ToolWhat it does
rpm2cpioConverts the RPM package into a CPIO data stream
cpioExtracts files from that CPIO stream

The flow looks like this:

Neither step installs the package, and neither runs the package's install scripts.

2. Inspecting the Package First ​

Before extracting anything, it helps to know what you're dealing with. Take this package as our example:

bash
demo-app-1.0.0-1.el7.x86_64.rpm

2.1 Basic package info ​

bash
rpm -qip demo-app-1.0.0-1.el7.x86_64.rpm

2.2 List the files inside ​

bash
rpm -qpl demo-app-1.0.0-1.el7.x86_64.rpm

Sample output:

text
/usr/bin/demo-app
/usr/lib64/libdemo.so
/usr/share/doc/demo-app/README
/etc/demo-app/config.yaml

2.3 Check the dependencies ​

bash
rpm -qpR demo-app-1.0.0-1.el7.x86_64.rpm

2.4 Check the architecture ​

bash
rpm -qp --qf '%{ARCH}\n' demo-app-1.0.0-1.el7.x86_64.rpm

3. Extracting the Package (CentOS 7) ​

This is the part you actually came for.

3.1 Create the output directory ​

bash
mkdir -p ./output

3.2 Step into it ​

bash
cd ./output

3.3 Extract ​

bash
rpm2cpio ../demo-app-1.0.0-1.el7.x86_64.rpm | cpio -idmv

Flag by flag:

FlagMeaning
-iExtract files from the CPIO archive
-dCreate any directories it needs
-mPreserve file modification times
-vPrint each file as it's extracted

When it finishes, everything inside the package sits in your current directory.

3.4 Check what came out ​

bash
find ./ -type f

The resulting tree looks roughly like this:

text
output/
├── etc/
│   └── demo-app/
│       └── config.yaml
├── usr/
│   ├── bin/
│   │   └── demo-app
│   ├── lib64/
│   │   └── libdemo.so
│   └── share/
│       └── doc/
│           └── demo-app/
│               └── README

Worth noting: the absolute paths inside the package (/usr/bin and friends) come back as relative paths under your output directory. Nothing gets written into the real /usr/bin on the system.

4. The CentOS 7 Gotcha ​

On CentOS 7 you might be tempted to point cpio at an output directory directly:

bash
rpm2cpio package.rpm | cpio -idmv -D ./output

and get this instead:

text
cpio: invalid option -- 'D'
Try `cpio --help' or `cpio --usage' for more information.

The reason is simple: the cpio that ships with CentOS 7 is old enough that it never learned the -D flag.

The Fix ​

Skip -D. Change into the target directory first, then extract:

bash
mkdir -p ./output

cd ./output

rpm2cpio ../package.rpm | cpio -idmv

This is the approach that has actually been verified to work on CentOS 7.

Heads-up: the ../package.rpm above assumes the RPM file lives one level above output.

5. FAQ ​

5.1 Does extracting an RPM need root? ​

No.

As long as your user can write to the output directory, the extraction will succeed. Running as a normal user in a dedicated directory is the better habit anyway — no surprise writes to system paths.

5.2 Will extraction run the package's install scripts? ​

No.

rpm2cpio and cpio only unpack files from the archive. Scriptlets like %pre and %post are never executed.

5.3 Can I run the extracted binary right away? ​

Not necessarily.

The files are there, but the binary may still rely on shared libraries, a runtime, or other resources provided by the target system.

Check its shared library dependencies with:

bash
ldd ./output/usr/bin/demo-app

Or look at the ELF metadata:

bash
file ./output/usr/bin/demo-app

5.4 How do I confirm everything was extracted? ​

Compare the package's file list against what landed on disk:

bash
rpm -qpl package.rpm
bash
find ./output -type f

Just remember the path prefixes differ between the two outputs — strip or rewrite them before diffing.

6. Wrapping Up ​

If you're on CentOS 7 and need a package's contents without installing it, the recipe is:

bash
mkdir -p ./output

cd ./output

rpm2cpio ../package.rpm | cpio -idmv

What you get out of it:

  • No package installation.
  • No install scripts executed.
  • No automatic changes to system directories.
  • No need to resolve the package's dependencies.
  • Binaries, shared libraries, config files and other assets, all extractable.

The idea in one line: convert the RPM with rpm2cpio, unpack the stream with cpio.

Last updated on11/23/2026, 06:57 AM
@fishfinal | @fishfinals | [email protected]