How to extract files from an RPM package on Linux

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.

On Ubuntu, Debian or Linux Mint:

$ sudo apt-get install rpm2cpio

On 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.

  • -i: extract files
  • -d: make directories
  • -m: preserve modification time
  • -v: verbose

Download this article as ad-free PDF (made possible by your kind donation): 
Download PDF

Subscribe to Ask Xmodulo

Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.


Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

Leave a comment

Your email address will not be published. Required fields are marked *