nixCraft Poll

Topics

How to extract an RPM package without installing it

Posted by Vivek Gite [Last updated: July 10, 2007]

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?

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

Example

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:

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.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Smith Data Processing Services » Blog Archive » links for 2006-10-22 Says:

    [...] How to extract an RPM package without installing it | nixCraft (tags: linux rpm extraction) [...]

  2. Ivan Says:

    You can also use alien package to convert rpm to tgz…

  3. nixcraft Says:

    Thanks for pointing out alien package to convert rpm to tgz.

  4. Jared Says:

    thanks…worked first time

  5. Jared Says:

    I love it when I search Google and find a good answer right away.

    Thank you so much.

  6. Kulbir Saini Says:

    thanks a lot :)

  7. Robert Says:

    I just found this page and it is great. One thing to note is that opensuse compresses the cpio part with lzma to decrease size so you have to do something like the following instead.

    rpm2cpio file.rpm | lzma -d | cpio -idmv

    This will extract the files for you.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.