MandrakeUser.Org - Your Mandrake-Linux Knowledge Base!


 
 

* DocIndex - Basics

RPM II

* Preliminaries
* Common Operations
* Advanced Querying

Related Resources:

RPM usage for newbies
RPM and Computer Users
man rpm

Revision / Modified: Mar. 14, 2002
Author: Tom Berger

 

* Preliminaries

Graphical Package Managers

I'm not going to discuss the handling of graphical package managers like Mandrake Linux' Software Manager, GnoRPM or KPackage here. They come with their own extensive online help. Furthermore will understanding the basics of the RPM system enable you to handle all of them.

Check out the Linux Demo and Tutorial Center for animated guides to KPackage and the Software Manager. The official Mandrake Linux 'Installation and User Guide' also dedicates a complete chapter to Package Management with the Software Manager.

Package Names

The name of an RPM consists of three parts: the archive name, the archive version number and the version number of the package.
Thus 'mc-4.5.51-7mdk.rpm' means: 'This package contains an archive called 'mc', version 4.5.51. It is the seventh revision of this particular package.' 'mdk' denotes the distribution (not mandatory).

Why an extra number for the package version? Packaging is a complex process. Sometimes the packager may overlook some detail and has to come up with a fixed package. Or maybe he or she just has discovered a way to make the package better. The package version number allows upgrading packages which contain the same version of an archive. Notice that a package version number can consist of two parts, separated by a full stop. This usually signifies a package which has been updated for security reasons.

Sooner or later you will encounter packages like 'mc-4.5.51-7mdk.src.rpm. These are Source RPMs. Unless you know what these are and how to handle them, they are of no use for you.

Archive Name Or File Name?

RPM discriminates between a not-installed and an installed package.
Operations on a not-installed package require the full file name as the argument to the RPM command, like

rpm -i mc-4.5.51-7mdk.rpm

to install the package 'mc-4.5.51-7mdk.rpm' on the local system.

If you are doing something involving an installed package, however, its archive name is required:

rpm -e mc

erases the package containing the 'mc' archive from the system. This works because you can't install two RPMs with the same archive name on the same system.
If you are trying to do something like

rpm -e mc-4.5.51-7mdk.rpm

you will get

error: package mc-4.5.51-7mdk.rpm is not installed

even if the package is installed.

* section index * top

* Common Operations

RPM accepts a sackful of options. Thankfully it is pretty obvious from their names what they do.
Most options come in two flavors: a long option and a short option. The long option features two hyphens and the full option name, the short one hyphen and - in most cases - the first character of the full option. Of course you only have to provide one option form, i.e. either rpm --installpackage or rpm -i package.

If the argument to RPM is a file name, you can use globbing patterns to specify a set of files, e.g.:

rpm -i bla*

will install all packages in the current directory which begin with the string 'bla'. Operations which require the archive name, however, donot accept them:

rpm -e *gtk*
error: package *gtk* is not installed

Remember that RPM doesn't care whether not-installed packages are on a local file system or on a remote web or FTP server. Every operation on a not-installed package can be done remotely by supplying the full URL to the package(s):

rpm -qpi ftp://ftp.server.com/RPMS/bla*

gets the descriptions from all packages starting with 'bla' which are located in the 'RPMS' directory on ftp.server.com.

Installing, Upgrading, Removing

All of these commands require 'root' privileges.

  • rpm -i package installs a package.
  • rpm -e archive erases it.
  • rpm -U package upgrades an installed package with a newer version.
  • rpm -F packages freshens a set of RPMs. That is it will check which of the specified packages are installed in earlier versions and upgrade them in the correct order.

There are two special modifiers used in conjunctions with these options, '--test' and '--verbose' (or '-v').

'--test' only executes the command 'as if': that is you get all the messages RPM usually produces, but the command itself is not executed. This modifier has no short option.

'--verbose' ('-v') increases the amount of output RPM displays on the screen. This is especially useful in case of errors or together with the '--test' modifier. Adding another '-v' ('-vv') increases the level of verbosity even more.

Querying

These commands do not require 'root' privileges. Notice that when you are querying not-installed packages, you have to add the '-p' option to the '-q' option.

  • rpm -q archive queries for package name and version of an installed package:

    rpm -q mc
    mc-4.5.51-7mdk

  • rpm -qp package does the same on a package which isn't installed.
  • rpm -qi archive informs you about the package's purpose, who packaged it when and where, when it has been installed, its size etc. To query a not-installed package, run rpm -qpipackage
  • rpm -ql archive lists all file in an installed package.
  • rpm -qd archive lists alldocumentation files in an installed package.
  • rpm -qa lists all installed packages. Useful when used in combination with 'grep'.
  • rpm -qa --last lists all installed packages sorted by their installation date, newest first.
  • rpm -q --changelog archive displays the list of changes applied to a package by its maintainer(s).
  • rpm -qf file tells you which installed packagefile belongs to.

* section index * top

* Advanced Querying

Using additional utilities and the somewhat awkward '--queryformat' option, there's almost nothing you can't find out about a package or the local RPM database.

Looking For Installed Packages Matching A Pattern

A common problem: you want to check if a package is installed, but you don't remember it's exact name (or are too lazy to type it). Use

rpm -qa | grep -i pattern

This is a so-called pipe with the grep command (the '-i' option makes the search case insensitive). So, a command like

rpm -qa | grep -i xfree

will return a list of all installed packages with the string 'xfree' in them, regardless of capitalization.

Looking For A File In Uninstalled Packages

Another common problem: which package contains a certain file? Put your Mandrake CD into your drive (let's say it's '/mnt/cdrom') and type

for i in /mnt/cdrom/Mandrake/RPMS/*.rpm ; do rpm -qpli $i | grepfilename && echo $i ; done

This for-do loop will return the name of the package which containsfilename, if there is such a package on the CD. That's a tad tedious, advanced queries usually should be performed using the Mandrake Linux 'urpm' tools to be introduced on the next page.

Listing Installed Packages By Installation Size

If you've cared to read the introduction on the first page, you already know that RPMs are made with the help of spec files. The '--queryformat' option allows you to query each spec file field of any given RPM separately and in any preferred order. Enter

rpm --querytags

to get a list of all valid fields. The formatting is a bit complicated and best explained by means of an example.
Imagine you are short on disk space and want a list of all installed packages sorted by size to find out which package would be best to uninstall. This is what the command (one line) would look like:

rpm -qa --queryformat '%{name} %{size}\n' | sort -n +1 | column -t

Tough one, eh? ;) The first part does all the work: querying all packages by the 'querytags' 'name' and 'size' only (have to be enclosed in '%{[tag]}'). Since the 'querytags' string contains spaces, it has to be enclosed in single quotes. The '/n' inserts a line break after each line.
The 'sort' command sorts the output (largest package last) and 'column' makes two nicely separated columns: names on the left, size in bytes on the right. As long as you remember the special querytags formatting rules, you should have no trouble using this option.

You see that you can do a lot of nifty things with RPMs, but the more you want, the more complicated the RPM syntax gets. Other capabilities like the automatic resolution of dependencies or globbing of archive names are missing completely. Time for Mandrake Linux' 'urpm' ...

* section index * top

* RPM Mandrake Style: urpm


 
Legal: All texts on this site are covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB (Tom Berger) and Mandrakesoft 1999-2002.