[Linux for Newbies] Linux for Newbies, pt. 17

Linux for Newbies, pt. 17:
Installing and Updating Packages with RPM

by Gene Wilburn

(The Computer Paper, Dec 2000. Copyright © Wilburn Communications Ltd. All rights reserved)


One of the milestone events in the history of Linux was the development of the Red Hat Package Manager, or RPM. In the early days of Linux there was no widely-used package manager--most packages were installed and updated by hand via tar files. Dependencies were something you worked out for yourself, and it was up to you to manage your config files. You often compiled every program from source code--not a bad thing in itself, but time-consuming and usually unnecessary. The need for a package manager for pre-compiled binaries was apparent and early attempts to come up with a solution included PM and RPP--predecessors to RPM.

When it developed and then began shipping RPM, Red Hat quickly took over as the leading Linux distribution--the position it has held to this day. It was simply a better way of managing the hundreds of packages on a Linux system. Red Hat released RPM under GPL and RPM is now used by many of the major Linux distributions.

The impact and importance of package managers is so fundamental that Linux distributions divide along package-manager lines. Slackware, which uses the old, relatively crude TGZ packaging, is the sole remaining distribution of the old school. Most of today's distros are RPM-based: Red Hat, Caldera, Mandrake, SuSE and Turbo. The only other package manager that has had major impact is the thoroughly excellent Debian DEB system, which lies at the heart of Debian GNU/Linux, Storm Linux and Corel Linux--all Debian-based systems.

The RPM system has been widely adopted in the industry. When major players such as Oracle and IBM release Linux versions of software, they are usually offered as RPM's. Using a distro such as Red Hat makes it easy to add new packages to your system.

RPM allows you to perform three major package management tasks: install, update, and delete. Let's start with an RPM overview.

RPM Basics

Because RPM is so popular and widely used, there are a number of graphical RPM tools and supplementary utilities that can be used with KDE and GNOME desktops. I would suggest, however, that you avoid using these and learn to use RPM directly from the command line. RPM commands are easy and you get better and more direct feedback by typing the commands.

Let's begin with the obvious. RPM packages have the extension .rpm. RPM files include a base name plus version information. Your Red Hat Linux installation CD has a directory called RPMS that contains all the RPMs for your current system. Here is a brief, edited list of some of the files that exist in the Red Hat 6.2 RPMS directory:

    # ls /mnt/cdrom/RedHat/RPMS/b* /mnt/cdrom/RedHat/RPMS/bash-1.14.7-22.i386.rpm /mnt/cdrom/RedHat/RPMS/bash2-2.03-8.i386.rpm /mnt/cdrom/RedHat/RPMS/bash2-doc-2.03-8.i386.rpm /mnt/cdrom/RedHat/RPMS/bc-1.05a-5.i386.rpm /mnt/cdrom/RedHat/RPMS/bdflush-1.5-11.i386.rpm /mnt/cdrom/RedHat/RPMS/bind-8.2.2_P5-9.i386.rpm /mnt/cdrom/RedHat/RPMS/bind-devel-8.2.2_P5-9.i386.rpm /mnt/cdrom/RedHat/RPMS/bind-utils-8.2.2_P5-9.i386.rpm /mnt/cdrom/RedHat/RPMS/binutils-2.9.5.0.22-6.i386.rpm /mnt/cdrom/RedHat/RPMS/bison-1.28-2.i386.rpm /mnt/cdrom/RedHat/RPMS/bzip2-0.9.5d-2.i386.rpm

RPM Queries

Let's use bc as an example. This program--binary calculator--is a handy little command-line calculator. It's not essential to your system, but it's nice to have. How can you tell if it's installed? We'll use the RPM query function:

    # rpm -q bc package bc is not installed

RPM commands begin with "rpm" and flags are used to designate actions. In this case we used the "-q" query flag followed by the name of the package we want to check. Notice that although the RPM package is named bc-1.05a-5.i386.rpm, we only query the basename, bc. The versioning information begins at the first hyphen. Thus "-1.05a-5.i386" tells us that this is version 1.05a-5 compiled for Intel 386 architecture.

RPM Uninstalls

You may already have bc installed on your system. If you want to do your first RPM practice on a low-risk package, and bc is already installed, here's how to uninstall it:

    # rpm -e bc #

In this case we used the "-e" erase or delete package flag. Unless there are dependencies, the uninstall process (rpm -e) is silent, meaning that RPM doesn't say anything like "bc is uninstalled".

RPM Installs

Now let's install bc. Move to your RPMS directory with the cd command, and type the following:

    # rpm -ihv bc-*.rpm bc ##################################################

It's the install flag (-i) that does the install. The -h flag simply puts a line of hash marks across the screen to indicate activity. The "-v" flag adds more information--in this case the name of the package being installed. Nice when you're installing several packages at the same time. You can leave out the -h and -v options and simply do "rpm -i bc-*.rpm" and it will install silently. I prefer to see the activity and any additional information.

Check to make sure bc is installed by trying it out:

    # bc bc 1.05 Copyright 1991, 1992, 1993, 1994, 1997, 1998 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY. For details type `warranty'. 47 * 47 - 200 2009 quit

RPM Updates

One of the key uses for RPM is for updating existing packages. Whether you update because you need newer features or you update because of a security alert, the method is the same. First obtain the new RPM file from a website. Use www.redhat.com/mirrors.html to locate a good mirror site for official Red Hat updates. You should apply all security updates as they are announced.

In its simplest form, the update command is

    # rpm -U package.rpm

but I prefer

    # rpm -Uhv package.rpm

As in the install example the "-h" flag displays hash marks to indicate activity and the "-v" flag displays additional information.

The update flag is slightly misleading. What it actually does is first install the package, then erase all older versions of the package, if any exist. Because of these procedures, -U can actually be used in place of -i for just about everything except kernel installs. In fact, this is the recommended usage: -U instead of -i for most installs of new software.

An Update Example: MySQL

Let's take an example. I am a big fan of the open-source database package MySQL--a lightweight SQL server that is very fast and makes a good back end to dynamic web pages. Every so often I like to update to the latest version. First I go to the command line and query my current version:

    # rpm -q MySQL MySQL-3.22.32-1

A quick check at the MySQL web site (www.mysql.com) shows the latest release to be 3.23.25 and I want to update, even though this version is considered beta. I first download the RPM files for Intel. On my system I like to keep RPM update files in two directories: /usr/local/src/redhat/62update for official Red Hat RPM update files, and /usr/local/src/redhat/contrib for non-Red Hat RPM files. The MySQL RPM files will be placed in the "contrib" directory.

After downloading I have the following files in my contrib directory:

    # ls MySQL* MySQL-3.22.32-1.i386.rpm MySQL-devel-3.22.32-1.i386.rpm MySQL-3.23.25-1.i386.rpm MySQL-devel-3.23.25-1.i386.rpm MySQL-client-3.22.32-1.i386.rpm MySQL-shared-3.23.25-1.i386.rpm MySQL-client-3.23.25-1.i386.rpm

I now have two sets of RPM files for MySQL--the older 3.22.32 which I will keep around in case this doesn't work out, and the newer 3.23.25 files. I will first update to MySQL-3.23.25 (the server itself) and then update the client, devel and shared RPMs. But first I have to stop MySQL which is currently running:

    # /etc/rc.d/init.d/mysqld stop

Now I can update the MySQL server RPM:

    # rpm -Uhv MySQL-3.23*rpm MySQL ################################################## PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! This is done with: /usr/bin/mysqladmin -u root -p password 'new-password' /usr/bin/mysqladmin -u root -h darwin -p password 'new-password' See the manual for more instructions. ... Starting mysqld daemon with databases from /var/lib/mysql

After the server is updated, I proceed with the updates for the client, development and shared RPMs:

    # rpm -Uhv MySQL-client-3.23*.rpm MySQL-client ################################################## # rpm -Uhv MySQL-devel-3.23*.rpm MySQL-devel ################################################## # rpm -Uhv MySQL-shared-3.23*.rpm MySQL-shared ##################################################

I restart MySQL and check that I can connect via the client, typing a simple SQL statement:

    # /etc/rc.d/init.d/mysqld start # mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 to server version: 3.23.25-beta Type 'help;' or '\h' for help. Type '\c' to clear the buffer mysql> show databases; +----------+ | Database | +----------+ | mysql | | test | +----------+ 2 rows in set (0.00 sec) mysql> quit Bye

All is well, and I'm ready to use version 3.23.25--until the next time I upgrade.

RPM and configuration files

Okay you say, not too hard, but what happens to configuration files? Let's say you want to update Apache or Samba and have spent hours configuring the products. Is RPM smart enough to not blow away all that work?

The answer is yes! RPM takes great care with config files. The standard way of dealing with them is to put aside your current version by renaming your existing config file along the lines of httpd.conf.rpmsave or leaving your file intact and adding the new stock config file as httpd.conf.rpmorg. Because a newer version of a product often has more things to configure, it is up to you to merge the new and the old manually, but nothing is lost from your original configuration. Samba does it slightly differently. It preserves your existing file but puts the new one (with more options) as smb.conf.rpmnew.

RPM Tricks and Tips

With the preceding information, you should now be able to obtain new software packages and install or update them. The basics of RPM are -i for install, -e for erase, and -U for update. This really only scratches the surface, of course. RPM has a huge number of flags that you can use to cover various situations. (Building or adjusting RPM packages from source files is a separate, advanced topic. The reference at the end of this column has the instructions should you become interested enough to want to learn how to create or modify your own RPMs.)

There are a few tricks you can do with RPM that are very useful. Remember the -q query flag? When combined with -a, it queries all your RPMs. You can then pipe these through grep to search for packages that you think might be installed. Here's how it would work for MySQL:

    # rpm -qa | grep -i mysql MySQL-client-3.23.25-1 MySQL-devel-3.23.25-1 MySQL-shared-3.23.25-1 MySQL-3.23.25-1

Say you want to know what package owns /usr/bin/paste. You can do this query:

    # rpm -qf /usr/bin/paste textutils-2.0e-6

Want to see what the textutils package is all about? Try this:

    # rpm -qi textutils Name : textutils Relocations: (not relocateable) Version : 2.0e Vendor: Red Hat, Inc. Release : 6 Build Date: Thu 22 Jun 2000 03:22:43 PM EDT Install date: Sat 22 Jul 2000 07:21:54 AM EDT Build Host: porky.devel.redhat.com Group : Applications/Text Source RPM: textutils-2.0e-6.src.rpm Size : 1769974 License: GPL Packager : Red Hat, Inc. Summary : A set of GNU text file modifying utilities. Description : A set of GNU utilities for modifying the contents of files, including programs for splitting, joining, comparing and modifying files.

There are also flags for updating or creating the RPM database itself. As always, man is your friend. Type "man rpm" for a quick reference.

Advanced RPM

For day-to-day use, the man pages for RPM will suffice but if you really want to explore this package and even learn to create your own RPMs, the definitive guide is Maximum RPM, Ed Bailey, Red Hat Press, 1997 (ISBN 0672311054 $56.95). A Postscript version of the book is available for downloading at www.rpm.org. While in an X session just gunzip the maximum-rpm.ps.gz file then use gv (Ghostview--a Postscript reader with similarities to Acrobat) to read it:

    # gv maximum-rpm.ps &

If gv is not on your system, hey, you now know what to do! Happy reading.

Gene Wilburn (gene@wilburn.ca) is a Toronto-based IT specialist, musician and writer who operates a small farm of Linux servers.

-30-