«
»

How to extract RPM or DEB packages

January 28th, 2008 by George Notaras

RPM and DEB packages are both containers for other files. An RPM is some sort of cpio archive. On the other hand, a DEB file is a pure ar archive. So, it should be possible to unpack their contents using standard archiving tools, regardless of your distribution’s package format. Under normal conditions, you should use your distribution’s standard package manager, rpm or dpkg and their frontends, to manage those files. But, if you need to be more generic, here is how to do it.

RPM

For RPMs you need two command line utilities, rpm2cpio and cpio. Extracting the contents of the RPM package is an one-step process:

rpm2cpio mypackage.rpm | cpio -vid

If you just need to list the contents of the package without extracting them, use the following:

rpm2cpio mypackage.rpm | cpio -vt

The -v option is used in order to get verbose output to the stdout. If you don’t need it, you can safely omit this switch. For more information about the cpio options, please refer to the cpio(1) manual page.

DEB

DEB files are ar archives, which contain three files:

  • debian-binary
  • control.tar.gz
  • data.tar.gz

As you might have already guessed, the needed archived files exist in data.tar.gz. It is also obvious that unpacking this file is a two-step process.

First, extract the aforementioned three files from the DEB file (ar archive):

ar vx mypackage.deb

Then extract the contents of data.tar.gz using tar:

tar -xzvf data.tar.gz

Or, if you just need to get a listing of the files:

tar -tzvf data.tar.gz

Again the -v option in both ar and tar is used in order to get verbose output. It is safe not to use it. For more information, read the man pages: tar(1) and ar(1).

If anyone knows an one-step process to extract the contents of the data.tar.gz, I’d be very interested in it!

Update

As Jon suggested in the comment area, the contents of data.tar.gz can be extracted from the DEB package in a one step process as shown below:

ar p mypackage.deb data.tar.gz | tar zx

That will do it.

The How to extract RPM or DEB packages by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Terms and conditions beyond the scope of this license may be available at www.g-loaded.eu.

Related Articles

Tags: , , , , ,

Bookmark and Share

7 Responses to “How to extract RPM or DEB packages”

  1. knud Says :

    Please also try these:
    ‘rpm -qpvl package.rpm’
    ‘rpm -qpvl package.rpm > textfile’
    ‘less package.rpm’
    ‘lesspipe… > textfile’
    ‘less package.deb’
    ‘lesspipe… package.deb > textfile’
    And of course The Midtnight Commander ‘mc’ will open both rpm and deb.
    Rgds

  2. Jon Says :

    One-liner to extract data.tar.gz:

    ar p package.deb data.tar.gz|tar zx

  3. George Notaras Says :

    Jon: Excellent. Thanks for your feedback. I will update the post.

  4. Kilgore Trout Says :

    Is there a GUI program to do all this that will take any package and convert it to what you want?

  5. George Notaras Says :

    None that I know of. There is a command line tool though, called alien, which can convert packages between the RPM and DEB formats. Its use is very straightforward. I highly recommend you give it a shot.

  6. Johny Desmons Says :

    You can also extract deb files on Windows and Mac for free with AnyToISO program

  7. Steven Li Says :

    to extract RPM, I recommend p7z

Comments are automatically disabled after a certain period of time. Further discussion about the published content is still possible though in the G-Loaded Forums.