How do I extract an RPM package file without installing it on my Fedora Linux or CentOS or RHEL (Red Hat Enterprise Linux) Suse Linux?
Extracting rpm file command
To be frank there is no direct option available for rpm command to extract an RPM file. But there is a small nifty utility available called rpm2cpio. It rxtract cpio archive from RPM Package Manager (RPM) package. With the following hack you will be able to extract an RPM file.
First you use rpm2cpio to convert the .rpm file into a cpio archive on standard out. If a - argument is given, an rpm stream is read from standard in. The basic syntax is as follows:
pm2cpio 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
To extract RPM file using rpm2cpio and cpio command, type:
$ rpm2cpio php-5.1.4-1.esp1.x86_64.rpm | cpio -idmv
/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
In this example, output of rpm2cpio command piped to cpio command 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 the current directory:
etc php-5.1.4-1.esp1.x86_64.rpm usr var
Say hello to Midnight Commander
GNU Midnight Commander (mc) is a directory browser/file manager for Unix-like operating systems. Install mc using the following [nixcmd name="yum"]:
# yum install mc
Opening an RPM file using Midnight Commander (mc)
You can use mc command as follows to browse or extract rpm files:
Next select an RPM file (such as php-5.3*.rpm) by highlighting the package name and press Enter key. You need to select CONTENTS.cpio file:
To view/edit/extract files click or press on the special function keys. In this example, I pressed F3 function key to view php.conf file:
I hope you will find these tips useful to extract configuration file or other file without installing an RPM file.
- Man pages [man]rpm(8),cpio(1),rpm2cpio(1),mc(1)[/man]
- GNU Midnight Commander home page.