How To Extract an RPM Package Without Installing It (rpm extract command)

Most of you may know to how extract a tarballs and/or a zip files. Someone recently PM me with a question:

How do I extract an RPM package without installing it on my Fedora Core Linux v5?

Extract rpm File

To be frank there is no direct RPM option available via rpm command to extract an RPM file. But there is a small nifty utility available called rpm2cpio. It Extract cpio archive from RPM Package Manager (RPM) package. With the following hack you will be able to extract an RPM file.

So rpm2cpio converts the .rpm file specified as a single argument to a cpio archive on standard out. If a – argument is given, an rpm stream is read from standard in.

Syntax is as follows:

rpm2cpio myrpmfile.rpm
rpm2cpio - < myrpmfile.rpm
rpm2cpio myrpmfile.rpm | cpio -idmv

Examples – Extract files from rpm

Download an RPM file:
$ mkdir test
$ cd test
$ wget http://www.cyberciti.biz/files/lighttpd/rhel4-php5-fastcgi/php-5.1.4-1.esp1.x86_64.rpm
Extract RPM file using rpm2cpio and cpio command:
$ rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmvOutput:

/etc/httpd/conf.d/php.conf
./etc/php.d
./etc/php.ini
./usr/bin/php
./usr/bin/php-cgi
./usr/lib64/httpd/modules/libphp5.so
./usr/lib64/php
./usr/lib64/php/modules
....
.....
..
./var/lib/php/session
./var/www/icons/php.gif
19188 blocks

Output of rpm2cpio piped to cpio command (see how to use cpio) with following options:

  • i: Restore archive
  • d: Create leading directories where needed
  • m: Retain previous file modification times when creating files
  • v: Verbose i.e. display progress

Verify that you have extracted an RPM file in current directory:
$ ls Output:

etc  php-5.1.4-1.esp1.x86_64.rpm  usr  var

This is useful if you want to extract configuration file or other file w/o installing an RPM file.

GD Star Rating
loading...
GD Star Rating
loading...

Related Articles

Random Articles

Post a Comment