Introduction to Yum

Learn how to use yum, a tool for automatically maintaining your system. You can use yum to make sure your entire system is up to date, or to automatically add or remove applications and services.

Introduction

Installing and updating software can be one of the more unpleasant computer maintenance tasks. The process of inserting CDs, browsing for a particular app, answering install questions, looking for the right version, etc, can be boring and time consuming.

What one wants, ideally, is to be able to say to the computer, “install the latest version of OpenOffice,” and then the computer would go out and do just that. Or, one might like to ask the computer to automatically “make sure you are up to date.” Linux doesn’t offer any features quite that fancy, but modern distributions come with tools like yum, urpmi, YaST and rpmapt (or debian apt) which come close to providing these advanced features. The GUI based up2date project that ships with Fedora and Redhat is also useful. However, I have found that up2date on Fedora Core 2 is not entirely bug free, which is what led me to yum. After trying yum a few times, I found that it is much more powerful and useful than up2date.

These various tools are often associated with particular distributions. For instance, apt is native to Debian, urpmi to Mandrake, and yast to SUSE. Yum is usually associated with RedHat and Fedora, though like apt, it can be used on multiple distributions.

Yum is the Yellowdog Updater, Modified. It is very easy to use. For instance, if you have yum installed properly, then you can issue a command like this to install OpenOffice:

yum install openoffice

OpenOffice, and any dependencies on which it relies, will be automatically installed. In other words, all the packages necessary to install the most recent version of openoffice will automatically be downloaded from the Internet and installed.

To make sure your entire system is up to date, you can issue this command:

yum update

After issuing this command, any out of date files will be updated, and any missing dependencies will be installed. If a new version of one piece of software requires that another piece of software be updated, that task will be accomplished for you automatically.

The rest of this article will describe how yum works, how to install it, how to configure it, and how to perform routine tasks with it. If you understand how yum works, then you should have little trouble understanding either apt or urpmi.

Installing Yum

Yum is part of the Fedora Core standard install. If yum is installed, then you can become root and type yum to test it:

[root@somecomputer etc]# yum
    Usage:  yum [options] 
         Options:
          -c [config file] - specify the config file to use
          -e [error level] - set the error logging level
          -d [debug level] - set the debugging level
          -y answer yes to all questions
          -t be tolerant about errors in package commands
          -R [time in minutes] - set the max amount of time to randomly run in.
          -C run from cache only - do not update the cache
          --installroot=[path] - set the install root (default '/')
          --version - output the version of yum
          --exclude=some_pkg_name - packagename to exclude - you can use
            this more than once
          --download-only - only download packages - do not run the transaction
          -h, --help this screen

If yum is not on your system, you can download it from the Duke web site. Here is a download directory where all the versions of yum are kept. Information on downloading Yum for RedHat 9 or 8 is available at the Fedora Wiki.

Yum usually comes in the form of a rpm file, which can be installed like this:

rpm -Uhv yum-2.0.7-1.noarch.rpm

RPM is the Redhat package manager, and it is used to automatically install packages that are already on your system. After you have installed yum, then you can use yum to install or update all the other applications or services on your machine. In other words, you would only have to manually use rpm to install yum, and after that yum would control rpm for you automatically. Yum is much more powerful and much easier to use than rpm.

Configuring Yum

Yum needs to know what software should be installed on your system. For instance, if you are using Fedora Core 2, then it needs to know what packages make up a standard install of Fedora Core 2. The packages needed for a particular Linux distribution are stored in repositories on the Internet. To properly configure yum, you need to open a file called /etc/yum.conf, and make sure it contains the proper information. In other words, you use yum.conf to point yum at the repositories on the Internet that define the files needed for your distribution of Linux.

If you have installed Fedora Core from CD, then you probably have a valid yum.conf file on your system already. However, at the end of this article you will find a simple yum.conf file for RedHat 9, and a more complex yum.conf file for FedoraCore. These are complete files, and can be used to replace your existing yum.conf file; though of course I would recommend backing up any file you wish to replace.

Additional information on config files are found in various places across the web, including the information found at the following URLs:

  • http://www.fedoraforum.org/forum/archive/index.php/t-2067.html
  • ttp://www.xades.com/proj/fedora_repos.html
  • ttp://dries.studentenweb.org/apt/

Yum Packages

I’ve talked several times in this article about yum packages. A package in yum is an rpm file. Each rpm file has a header, that defines the contents of the file and any dependencies it might have. In particular, it defines the versions of the programs upon which the code in the rpm file depends. Using this header, it is possible to calculate exactly what packages (rpm files) need to be downloaded in order to successfully install a particular product.

When you first start yum by becoming root and typing yum list, it usually spends a long time (15 to 60 minutes) downloading not entire rpm files, but instead the headers for all the rpm files that define your distribution. After it has downloaded all these headers, then you can issue a command like yum update, and yum will compare the current contents of your system to the records found in the rpm headers it has downloaded. If some of the headers reference files that are more recent than the files currently installed on your system, then yum will automatically download the needed complete rpm files and use them to update your system.

Besides the headers for your distribution, you can configure yum to reference other repositories that contain additional files that might interest you. For instance, you can ask yum to download all the headers for the files needed to install mono, or all the fedora extras, or all the files that are part of jpackage. Once the headers are in place, you can download all or part of the packages found in these repositories. You can also point yum at freshrpms, a location where yum is likely to find any number of packages that might interest a Linux user. The complex yum.conf file at the end of this article is set up to do most of these things automatically. In another technical article which will soon appear on this site, I will discuss configuring yum so that it will automatically install mono.

If you want to visit a yum repository to see its structure, you can do so. Here, for instance, is the yum repository for Mandrake:

http://mirrors.usc.edu/pub/yum-repository/mandrake/

The Yum Cache

Yum stores the headers and rpms that it has downloaded on your system. Here is the directory structure that yum uses for its cache on of my old RedHat systems:

var/cache/yum
var/cache/yum/base
var/cache/yum/base/headers
var/cache/yum/base/packages
var/cache/yum/updates
var/cache/yum/updates/headers
var/cache/yum/updates/packages

As you can see, the cache is divided up into two sections, the base files and the updates. The headers for each section are stored in one directory, and any downloaded packages in another directory.

If you look at the simple yum.config file at the end of this article, you will see that defines where the cache will be stored, and that it has two sections called base and updates. The more complex yum.config file points at the same cache, but it has more repositories upon which it draws. As a result, using it will likely lead to you have more than two simple sections called base and updates. For instance, you might have sections called jpackage or updates-released.

Running Yum Update

As always, there is no better way to learn how yum works than simply getting your hands dirty at the command line by using it. The closest I can come to that experience in an article of this type is show you the output at the command line of the simple command yum update. At the time I ran this command, my system was already reasonably up to date, so only a few files are downloaded. The complete run is shown in Listing 1.

Listing 1: A simple run of yum update has three parts, first contacting the servers, then downloading the headers and parsing them, then downloading and installing the needed packages.

[root@somecomputer etc]# yum update
Gathering header information file(s) from server(s)
Server: Fedora Core 2 - i386 - Base
Server: Fedora.us Extras (Stable)
Server: Fedora.us Extras (Testing)
Server: Fedora.us Extras (Unstable)
Server: Livna.org - Fedora Compatible Packages (stable)
Server: Livna.org - Fedora Compatible Packages (testing)
Server: Livna.org - Fedora Compatible Packages (unstable)
Server: macromedia.mplug.org - Flash Plugin
Server: Fedora Core 2 - i386 - Released Updates
Finding updated packages
Downloading needed headers
cups-libs-1-1.1.20-11.6.i 100% |=========================| 6.8 kB   00:00
redhat-artwork-0-0.96-2.i 100% |=========================| 102 kB   00:00
libxml2-0-2.6.15-2.i386.h 100% |=========================| 3.0 kB   00:00
libxml2-python-0-2.6.15-2 100% |=========================| 4.3 kB   00:00
cups-1-1.1.20-11.6.i386.h 100% |=========================|  23 kB   00:00
perl-HTML-Template-0-2.7- 100% |=========================| 2.2 kB   00:00
jhead-0-2.2-0.fdr.1.2.i38 100% |=========================| 1.7 kB   00:00
cups-devel-1-1.1.20-11.6. 100% |=========================| 7.0 kB   00:00
libvisual-devel-0-0.1.6-0 100% |=========================| 2.4 kB   00:00
libvisual-0-0.1.6-0.fdr.2 100% |=========================| 1.9 kB   00:00
perl-Glib-0-1.061-0.fdr.2 100% |=========================| 4.4 kB   00:00
libxml2-devel-0-2.6.15-2. 100% |=========================|  14 kB   00:00
Resolving dependencies
Dependencies resolved
I will do the following:
[update: cups-libs 1:1.1.20-11.6.i386]
[update: redhat-artwork 0.96-2.i386]
[update: libxml2 2.6.15-2.i386]
[update: libxml2-python 2.6.15-2.i386]
[update: cups 1:1.1.20-11.6.i386]
Is this ok [y/N]: y
Downloading Packages
Getting cups-libs-1.1.20-11.6.i386.rpm
cups-libs-1.1.20-11.6.i38 100% |=========================| 101 kB   00:00
Getting redhat-artwork-0.96-2.i386.rpm
redhat-artwork-0.96-2.i38 100% |=========================| 4.4 MB   00:28
Getting libxml2-2.6.15-2.i386.rpm
libxml2-2.6.15-2.i386.rpm 100% |=========================| 625 kB   00:03
Getting libxml2-python-2.6.15-2.i386.rpm
libxml2-python-2.6.15-2.i 100% |=========================| 435 kB   00:02
Getting cups-1.1.20-11.6.i386.rpm
cups-1.1.20-11.6.i386.rpm 100% |=========================| 2.5 MB   00:16
Running test transaction:
Test transaction complete, Success!
libxml2 100 % done 1/10
cups-libs 100 % done 2/10
redhat-artwork 100 % done 3/10
libxml2-python 100 % done 4/10
cups 100 % done 5/10
Completing update for cups-libs  - 6/10
Completing update for redhat-artwork  - 7/10
Completing update for libxml2  - 8/10
Completing update for libxml2-python  - 9/10
Completing update for cups  - 10/10
Updated:  cups-libs 1:1.1.20-11.6.i386 redhat-artwork 0.96-2.i386
libxml2 2.6.15-2.i386 libxml2-python 2.6.15-2.i386 cups
1:1.1.20-11.6.i386
Transaction(s) Complete
[root@somecomputer etc]#

You can probably parse that file with no trouble on your own. However, I will take a few moments to break it apart, just you can be absolutely clear about what happens when yum performs an operation of this type.

The first step is to contact the server specified in your yum.conf file:

Gathering header information file(s) from server(s)
Server: Fedora Core 2 - i386 - Base
Server: Fedora.us Extras (Stable)
Server: Fedora.us Extras (Testing)
Server: Fedora.us Extras (Unstable)
Server: Livna.org - Fedora Compatible Packages (stable)
Server: Livna.org - Fedora Compatible Packages (testing)
Server: Livna.org - Fedora Compatible Packages (unstable)
Server: macromedia.mplug.org - Flash Plugin
Server: Fedora Core 2 - i386 - Released Updates

Yum then downloads the headers it found on the servers:

Finding updated packages
Downloading needed headers
cups-libs-1-1.1.20-11.6.i 100% |=========================| 6.8 kB   00:00
redhat-artwork-0-0.96-2.i 100% |=========================| 102 kB   00:00
libxml2-0-2.6.15-2.i386.h 100% |=========================| 3.0 kB   00:00
libxml2-python-0-2.6.15-2 100% |=========================| 4.3 kB   00:00
cups-1-1.1.20-11.6.i386.h 100% |=========================|  23 kB   00:00
perl-HTML-Template-0-2.7- 100% |=========================| 2.2 kB   00:00
jhead-0-2.2-0.fdr.1.2.i38 100% |=========================| 1.7 kB   00:00
cups-devel-1-1.1.20-11.6. 100% |=========================| 7.0 kB   00:00
libvisual-devel-0-0.1.6-0 100% |=========================| 2.4 kB   00:00
libvisual-0-0.1.6-0.fdr.2 100% |=========================| 1.9 kB   00:00
perl-Glib-0-1.061-0.fdr.2 100% |=========================| 4.4 kB   00:00
libxml2-devel-0-2.6.15-2. 100% |=========================|  14 kB   00:00

Next the dependencies are calculated and the user is asked whether she wants to download the needed packages:

Resolving dependencies
Dependencies resolved
I will do the following:
[update: cups-libs 1:1.1.20-11.6.i386]
[update: redhat-artwork 0.96-2.i386]
[update: libxml2 2.6.15-2.i386]
[update: libxml2-python 2.6.15-2.i386]
[update: cups 1:1.1.20-11.6.i386]
Is this ok [y/N]: y

If the user gives permission, then the needed packages are downloaded:

Downloading Packages
Getting cups-libs-1.1.20-11.6.i386.rpm
cups-libs-1.1.20-11.6.i38 100% |=========================| 101 kB   00:00
Getting redhat-artwork-0.96-2.i386.rpm
redhat-artwork-0.96-2.i38 100% |=========================| 4.4 MB   00:28
Getting libxml2-2.6.15-2.i386.rpm
libxml2-2.6.15-2.i386.rpm 100% |=========================| 625 kB   00:03
Getting libxml2-python-2.6.15-2.i386.rpm
libxml2-python-2.6.15-2.i 100% |=========================| 435 kB   00:02
Getting cups-1.1.20-11.6.i386.rpm
cups-1.1.20-11.6.i386.rpm 100% |=========================| 2.5 MB   00:16

Finally, some tests are run to make sure everything is as it should be.

Running test transaction:
Test transaction complete, Success!

If the the calculations check out, then the packages are installed and the user is notified that the transaction is complete:

libxml2 100 % done 1/10
cups-libs 100 % done 2/10
redhat-artwork 100 % done 3/10
libxml2-python 100 % done 4/10
cups 100 % done 5/10
Completing update for cups-libs  - 6/10
Completing update for redhat-artwork  - 7/10
Completing update for libxml2  - 8/10
Completing update for libxml2-python  - 9/10
Completing update for cups  - 10/10
Updated:  cups-libs 1:1.1.20-11.6.i386 redhat-artwork 0.96-2.i386
libxml2 2.6.15-2.i386 libxml2-python 2.6.15-2.i386 cups
1:1.1.20-11.6.i386
Transaction(s) Complete

Basic commands Used with Yum

clean

yum clean

cleans up stuff.

provides

yum provides PackageName

Find out which packages provide a particular feature.

install

yum install PackageName

install a package or group of packages.

update a package

yum update PackageName

update a package or group of packages

update system

yum update

update everything currently installed

remove

yum remove PackageName

remove a package

check for updates

yum check-update

See if there are any updates available

search

yum search

Useful if you know something about a package, but not its name

list

yum list

list what packages are available. Many options.

info

yum info

Find information on a package.

upgrade

yum upgrade

Like update, but helpful for moving between distro versions, depricated.

It has been reported that in FC3 you need only type yum list recent to learn of packages added to the repository in the last seven days. In general, you can run yum with no parameters or with -h as a parameter in order to get a sense of what you can do with any particular version of the product. Typing man yum is also a good way to learn more about the various commands you can give when using yum.

No comments yet

Leave a Reply

You must be logged in to post a comment.