English
How to Extract 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:
| Tool | What it does |
|---|---|
rpm2cpio | Converts the RPM package into a CPIO data stream |
cpio | Extracts 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.rpm2.1 Basic package info
bash
rpm -qip demo-app-1.0.0-1.el7.x86_64.rpm2.2 List the files inside
bash
rpm -qpl demo-app-1.0.0-1.el7.x86_64.rpmSample output:
text
/usr/bin/demo-app
/usr/lib64/libdemo.so
/usr/share/doc/demo-app/README
/etc/demo-app/config.yaml2.3 Check the dependencies
bash
rpm -qpR demo-app-1.0.0-1.el7.x86_64.rpm2.4 Check the architecture
bash
rpm -qp --qf '%{ARCH}\n' demo-app-1.0.0-1.el7.x86_64.rpm3. Extracting the Package (CentOS 7)
This is the part you actually came for.
3.1 Create the output directory
bash
mkdir -p ./output3.2 Step into it
bash
cd ./output3.3 Extract
bash
rpm2cpio ../demo-app-1.0.0-1.el7.x86_64.rpm | cpio -idmvFlag by flag:
| Flag | Meaning |
|---|---|
-i | Extract files from the CPIO archive |
-d | Create any directories it needs |
-m | Preserve file modification times |
-v | Print 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 fThe resulting tree looks roughly like this:
text
output/
├── etc/
│ └── demo-app/
│ └── config.yaml
├── usr/
│ ├── bin/
│ │ └── demo-app
│ ├── lib64/
│ │ └── libdemo.so
│ └── share/
│ └── doc/
│ └── demo-app/
│ └── READMEWorth 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 ./outputand 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 -idmvThis 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-appOr look at the ELF metadata:
bash
file ./output/usr/bin/demo-app5.4 How do I confirm everything was extracted?
Compare the package's file list against what landed on disk:
bash
rpm -qpl package.rpmbash
find ./output -type fJust 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 -idmvWhat 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.