How to extract files from an RPM package on Linux

Last updated on August 5, 2020 by Dan Nanni

Question: I downloaded an RPM file (foo.rpm) from somewhere, and I would like to manually extract files from the RPM package. Is there an easy way to extract files from an RPM package without installing it?

An RPM package contains a set of files, typically compiled software binaries, libraries, and their development source files. These files are packaged in a cpio archive format, and finally wrapped in an RPM file along with any necessary package-specific metadata.

You can view the content of an RPM package with rpm or repoquery command.

If you want to extract files from an RPM package without installing it, here is how: first obtain a cpio archive from the RPM file, and then extract actual files from the cpio archive.

The following describes how to achieve this from the Linux command line.

Install Necessary Tools

First, install necessary command line tools.

For Ubuntu, Debian or Linux Mint:

$ sudo apt-get install rpm2cpio

For CentOS, Fedora or RHEL:

$ sudo yum install rpm

Extract Files from an RPM Package

Once the necessary tools are installed, proceed as follows. This will extract all files in foo.rpm into the current directory.

$ rpm2cpio foo.rpm | cpio -idmv

The rpm2cpio command extracts a cpio archive from an RPM file, and cpio command extract files from the cpio archive.

The options used with the cpio command are described as follows.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean