RPM – RedHat Package Manager

What does a RPM Package contain?

RPMs (*.rpm) typically include

1) the compiled programs and/or libraries needed for the package,
2) documentation
3) install, verify, and uninstall scripts
4) cryptographic signatures for each file in the package. This makes it easy to verify the integrity of the package.
5) It also includes a list of packages that it depends on, and a list of services that are provided by the package.

Where are the RPM packages stored?

RPM maintains a database of all installed packages in /var/lib/rpm/*. Included in the database is a list of all files installed by RPM and which package they belong to. The info on various files in this directory are as follows. This makes it a very powerful tool for finding out more about each package.

Basenames: Berkeley DB (Hash, version 8, native byte-order)
Conflictname: Berkeley DB (Hash, version 8, native byte-order)
__db.001: data
__db.002: X11 SNF font data, LSB first
__db.003: X11 SNF font data, LSB first
Dirnames: Berkeley DB (Btree, version 9, native byte-order)
Filemd5s: Berkeley DB (Hash, version 8, native byte-order)
Group: Berkeley DB (Hash, version 8, native byte-order)
Installtid: Berkeley DB (Btree, version 9, native byte-order)
Name: Berkeley DB (Hash, version 8, native byte-order)
Packages: Berkeley DB (Hash, version 8, native byte-order)
Providename: Berkeley DB (Hash, version 8, native byte-order)
Provideversion: Berkeley DB (Btree, version 9, native byte-order)
Pubkeys: Berkeley DB (Hash, version 8, native byte-order)
Requirename: Berkeley DB (Hash, version 8, native byte-order)
Requireversion: Berkeley DB (Btree, version 9, native byte-order)
Sha1header: Berkeley DB (Hash, version 8, native byte-order)
Sigmd5: Berkeley DB (Hash, version 8, native byte-order)
Triggername: Berkeley DB (Hash, version 8, native byte-order)

Install and Upgrade Commands

a) To simply install a package do

rpm -i package.rpm

where, “-i” is the Install parameter and “package.rpm” is the RPM you’re installing. You can add more parameters to the above command, try this:

rpm -ivh package.rpm

The “-v” is for verbose and “-h” for the hashing marks. It’ll print some “#” when unpacking and then installs the package. You can use “–percent” instead of “-h” if you want.

b) The above command maybe the first RPM command you’ve learned. Upgrading to a New package can be done in 2 ways, the Freshen way and by executing:

rpm -Uvh new-package.rpm

Note that the “-U” Upgrading option simple removes the old and installed package, then install the new one. The “-Uvh” can be used to install a package too, if the package does not exist on your system the new-package.rpm will be installed.

c) Now imagine the situation where the new version of Samba you’ve just installed is not compatible with your applications, what to do? Answer: Upgrade to the old version. You can call this a “Downgrade” if you want. The command for install the Old package will be:

rpm -Uvh –oldpackage Samba-old-version.rpm

Where “–oldpackage” option says that Samba package version is older than the one installed. The command will remove the installed version and then install the Samba-old-ver.rpm.


To install a package (i=install v=verbose h=show hash marks) => rpm -ivh <package>
To upgrade a package => rpm -Uvh <package>
To test a package to see how it would install (without installing, also checks dependencies) => rpm -Uvh –test <package>

Remove a Package

a) For simply remove a package do:

rpm -e package

Where “-e” is the Erase parameter and “package.rpm” is the RPM you’re removing.

b) To Simulate what will be done when a package is removed( actually the package is not removed).

rpm -e –test <package>

c) To Backup the package before removing it

rpm -e –repackage <package>

d) Dependancy on the package to be removed
If another package(s) depends on it, RPM will not permit the erase. You can see a list of packages that requires the RPM package you’re trying to erase by executing:

rpm -q –whatrequires kernel

In this case it will print the packages that depends on Kernel, here’s a sample output:

# rpm -q –whatrequires kernel

So if we are erasing a package, first try to find out what package(s) depends on it and possibly remove them. Forget the danger parameters “–nodeps” and “–force”. Almost everything can be done without these parameters.

Querying an Installed package

a) To Query an installed package do:

rpm -q <pkg-name>

Eg: rpm -q yum

Here we used the “-q” parameter, that indicates we’re executing a query. The above command will returns true(Shell variable $? = 0) if the yum package is installed. Note that you can also use the full name with version/release numbers like this:

rpm -q yum-2.0.4-2

b) To know all the packages installed in the system

rpm -qa

Querying an RPM file
To query an .rpm file

rpm -qpi <rpmfile>

Eg: rpm -qpi skype-
warning: skype- Header V3 DSA signature: NOKEY, key ID d66b746e
Name : skype Relocations: (not relocatable)
Version : Vendor: (none)
Release : fc5 Build Date: Thu 27 Sep 2007 10:16:26 PM IST
Install Date: (not installed) Build Host: linux-build.skype.net
Group : Applications/Internet Source RPM: skype-
Size : 16209093 License: Commercial
Signature : DSA/SHA1, Thu 27 Sep 2007 10:16:33 PM IST, Key ID 0275af82d66b746e
URL : http://www.skype.com/products/skype/linux/
Summary : Skype is free Internet telephony that just works
Description :
Skype – Take a deep breath

Skype is a little piece of software that lets you make free calls
to anyone else on Skype, anywhere in the world. And even though
the calls are free, they are really excellent quality.

* Make free Skype-to-Skype calls to anyone else, anywhere in the world.
* Call ordinary phones and mobiles at pretty cheap rates per minute.
* Group chat with up to 100 people or conference call with up to nine others.
* Free to download.

When using “-p” query parameter RPM knows that it’s treating a file, in this case the skype RPM package. Note that the “-i” parameter here is used in “Query Mode”, it’s not the install one.

To list what packages are required by some RPM package
a) To get a list of packages and programs that are required for instalation of some RPM package, execute the following:

rpm -qpR

The “-R” parameter stands for “Requires”. And here is an example:

# rpm -qpR vnc-server-4.0-0.beta4.3.2.i386.rpm
bash >= 2.0
rpmlib(CompressedFileNames) <= 3.0.4-1
rpmlib(PayloadFilesHavePrefix) <= 4.0-1

b) If you like to query a installed package, Kernel package as an example, then do the following:

rpm -qR kernel

Here’s the output of the example:

# rpm -qR kernel
rpmlib(VersionedDependencies) <= 3.0.3-1
modutils >= 2.4.18
initscripts >= 5.83
mkinitrd >= 3.2.6
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(CompressedFileNames) <= 3.0.4-1

To find to which package a file belongs

rpm -qf <path-of-file>

# rpm -qf /usr/bin/vlc

To list the files installed by a RPM package

a) To see the contents of the installed package

rpm -ql <pkg-name>

Eg: # rpm -ql cpp

b) To do the same for a package file(ex: cpp-3.3.2-1.i386.rpm) add the parameter “-p” indicating a RPM package:

rpm -qpl cpp-3.3.2-1.i386.rpm

To install a package directly from Internet? Can I use a proxy?
RPM can be used to install and update directly from the network. You don’t need to download the package and then installs it, RPM can do it for you. It supports both HTTP and FTP protocols. To install/upgrade from a FTP server, the syntax is:

rpm -Uvh ftp://user:pass@ftpserver/directory/package.rpm

You can exclude user/pass credentials and login as anonymous/ftp user if you want. The following command will connect using a Proxy Server and then lists the contents of the package “remote-package.rpm”:

rpm -qpl –ftpproxy proxyserver –ftpport port ftp://ftpserver/dir/remote-package.rpm

Where “proxyserver” can be the hostname or IP address of your Proxy Server as well as “port” is the listening port on that server. The same rules apply to HTTP protocol, so the following command uses a Proxy Server to query the required packages for “remote-package.rpm” installation:

rpm -qpR –httpproxy proxyserver –httpport port http://webserver/dir/remote-package.rpm

How can I simulate what will be done when executing “rpm -ivh new-kernel.rpm”?

You can simulate or test what will happen when executing a RPM command. It’s useful when doing critical updates or instalations and when you want to see if there will be any problem during the RPM process. The following command can be used to simulate a kernel installation:

rpm -ivh –test new-kernel.rpm

This will show what problems you may find when installing the new Kernel(space available, dependency problem, etc), if nothing appears, try adding more verbosity with “-vv” parameter. If all goes ok you will see the traditional “Preparing…” output.

Note that you can use the “–test” parameter combined with other RPM commands too.

Difference between “Freshen” and “Update” command

The “Update” command will upgrade a package if an old version is already installed. If an old version of the package is not installed, then it will install the package.

“Freshen” command is used to upgrade only installed packages.

To figure out the Kernel version(smp, bigmem) and base arch(i386, athlon)?

When upgrading or installing a new Kernel version from a RPM package, there are some points you need to pay attention: the arch type and the Kernel name/version. See Kernel upgrade notes for more details on upgrading commands.

To obtain these values from your installed and current Kernel issue the command:

rpm -q –qf “Kernel arch type is: %{ARCH}\nKernel name is: %{VERSION}\n” kernel

How can I make backups of my old packages when updating or removing them?

When updating or removing a package you can make backup of the removed package by executing the following commands, respectively:

rpm -Uvh –repackage new-package.rpm
rpm -e –repackage new-package.rpm

The backup RPMs will be generated on “_repackage_dir” RPM macro, usually /var/spool/repackage, check this for more details on macros. If some problem occurs, then use the following command to reinstall:

rpm -Uvh –oldpackage /var/spool/repackage/old-package.rpm

Verify commands
To verify a package (extra verbose output) rpm -Vvv To verify ALL installed packages on the system rpm -Va
To verify the cryptographic signature of a package rpm -K

RPM database broken.How can I get RPM back? The command “rpm -qa” returns nothing!

Sometimes the RPM database get broken and rpm command freezes or doesn’t work as expected. Here’s what can be done to solve this problem:

rm -f /var/lib/rpm/__* ; rpm -vv –rebuilddb ; rpmdb_verify Packages(optional)

The extra verbose is for printing some status on screen, the database rebuild process can take a long depending on your machine and package information.

How can I figure out the installation time of my packages?

The following commands are useful when you just had problems with recent installed packages, they’ll print a list of installed packages sorted by install time:

rpm -qa –queryformat ‘%{installtime} %{installtime:date} %{name}-%{version}\n’ | sort -n | sed ‘s/^[0-9]*//’
rpm -qa -last | tac

How can I figure out the size of a installed package?
The following RPM command is useful when you are having problems with less hard disk space, it’ll print a list of installed packages sorted by package size(in bytes):

rpm -qa –queryformat ‘%10{size} %{name}-%{version}\n’ | sort -n

Written by actsupp-r0cks