Chapter 38. Advanced yum

IN THIS CHAPTER:

Fedora is provided with a large amount of packages already supplied and ready to go. However, since Fedora Core 4, The Fedora Project has been on a mission to put Fedora on a massive “slim-fest,” mainly because the distribution and the number of packages included were beginning to get out of control. Now, Fedora is released with a core of software that is designed to get you up and running in any one of many different configurations such as a web server, development environment, or a database server. Consequently you are stuck with this core of software when you first install. However, Fedora also comes with a great package management tool, called yum, which enables you to quickly and easily download and install packages. The yum tool (Yellowdog Updater, Modified) has been included with Fedora since version 1 and has become the tool of choice for installing and updating applications. In this chapter, we will take a look at how yum works, its basic usage, and more advanced package and repository management.

yum is controlled entirely from the command line, so you will have to memorize some useful switches to get the most from it. But before we go into yum itself, it is worthwhile understanding what goes on behind the scenes. How does yum actually work?

It is easiest to think of yum as a software layer that utilizes the rpm command. When you issue commands to yum, it automatically accesses various repositories and downloads the rpm headers that are then queried using the rpm command. The advantage to this is that all the processing takes place locally, without the need to download the entire RPM itself. Typically, the RPM header makes up a very small portion of the file, which makes it easy to handle and quick to download. yum builds and maintains a local cache of header files, attributed to the supplying repository, and queries this when you use yum. Each time yum is invoked, it checks the repositories for any updates. If any are found, it adds new headers to its cache, thereby making it as up-to-date as possible when you need to use it. Because yum uses rpm, there should be no dependency problems, making it a fast and easy way to install and update software.

yum is primarily controlled by its configuration file, yum.conf, and by the contents of the yum.repos.d directory, both of which can be found in /etc. By default, yum uses the Red Hat and Fedora repositories for updates, but you can easily add more of your own if you want to install other software that is not available from Red Hat.

Like apt, yum is incredibly easy to use, requiring a single command with a switch to update all the software in Fedora.

Getting Started

First, open a terminal. Check that yum is installed and working by simply typing

$ yum

This brings up the usage options for yum and lets you know that you have it installed.

After you have verified that yum is available, you should switch to super-user and enter the following command:

# yum check-update

This command initializes yum and asks it to scan the installed RPMs on your machine, scan the repositories for header files, and then start building a cache of header files. After several minutes of frantic activity, yum will have completed its local cache of header files and will be ready for you to start downloading and installing updates and new software.

To perform a quick and easy update of all the software on your system, enter the following command:

# yum update

This asks yum to download header information from the registered repositories, check that against your current installed packages, and update any that are marked as having new versions. This can take some time, depending on how often you run the command and how many packages you have installed on your system. Of course, if you have a cable or DSL connection, it will be quicker, but dial-up users should be warned that they might need to go away and make a few cups of coffee while yum does its work.

When yum has finished downloading the headers and working out dependencies, you are prompted with a list of the packages to be updated or installed and asked to give the go-ahead. Enter y at the command prompt and yum commences downloading the RPM files.

After the download finishes, yum runs the installation and a test to ensure that everything completed correctly. When yum is satisfied that everything is present and correct, you are returned to the command prompt with a freshly updated system.

This is great when you want to update your entire system, but what if you want to update only certain packages? Again, yum can easily take care of this for you. You can identify the package you want and then use yum to check for its availability by using the command shown here:

# yum list <packagename>

This command asks yum to cross-reference the package name with packages registered at the repositories and let you know what is available. You can use wildcards as part of the command to find out which associated packages are available. For instance, the command

# yum list kde*

searches for any packages containing kde, which is useful if you want to selectively update packages. Use the command shown here to update a single package:

# yum update <packagename>

Or use this command to update more than one package at a time:

# yum update <packagename1> <packagename2>

Of course, when yum is processing the required packages, it also solves any dependency issues. You will get the opportunity to see not only the packages that will be updated, but also which packages were required to satisfy dependency issues.

Running yum Noninteractively

Running yum can involve a number of updates and dependency resolution, which can itself take a long time to download, especially if you are connected to the Internet via a slow connection. Even with a relatively good connection (2Mbps DSL) it can take a while to download a few hundred megabytes of packages. Thankfully there is an option within yum that you can use to make it run with minimal user intervention. The syntax looks like this:

#yum -y update

This tells yum that when a question is asked, it is to automatically assume the answer to be yes. This way you can go away and do other tasks rather than waiting for yum to finish downloading all the headers and to ask you whether you want to go ahead and install the packages.

Using yum to Remove Packages

So far we have looked at using yum only for installing software, but that is only a small part of its capabilities. It can also be used to remove packages that are no longer required, as well as to give detailed information on installed and available packages. The syntax is similar to the installation and update functions of yum. In this section, we look at removing packages from the system using yum.

As mentioned earlier, yum interfaces with the rpm command to use it for querying the local package database. If you need to remove a package, you can use yum remove <packagename>. yum then scans the local file system, finds the package named, and checks for potential dependency problems. This way, you will never remove a package that could crash your system. You are prompted to give confirmation that you want to remove the required package; then yum processes the packages and their dependencies to remove them safely.

Maintaining yum

Over time yum can build up a large cache of RPM headers and other assorted information that can gradually build up to occupy a sizeable amount of room on your hard drive. This cache is kept in /var/cache/yum and can be managed by using the yum command with your choice of options.

After yum finishes with the packages it downloads, it does not automatically delete them from the system even though you might have no further use for them. After only one invocation of yum update I found that my cache file had blossomed to just over 500MB in size. A few months down the line and this could grow exponentially as new updates, bug fixes, and security patches become available.

As with all things in Fedora, you get a choice as to what you want to remove: the packages themselves, the RPM header files, or both. To clean the system of just the packages, you should use the command

#yum clean packages

By doing this, yum removes all the downloaded packages on my system, saving me 450MB in one go.

If you want to remove the header files, too, you can use the command

#yum clean headers

This saves an extra 10MB on top of the 450MB that removing the packages gave me.

Note

If you decide to remove the header files, yum will have to redownload them the next time that you decide to update your system. This can take a little bit of time, but should not be a problem if you have a fast broadband connection.

Finally, if you want to remove both the packages and the headers in one quick step, you should use the command

#yum clean all

This removes all packages and headers from the cache. We suggest just using the command to clean the packages, especially if you are on a slow Internet connection, because keeping the headers will save you time in future updating sessions.

Using yum to Manage Package Inventory

Another useful feature of yum is its capability to list several sets of packages. There are a few options that you can list, including packages that are currently installed, packages that are available to be installed, and packages that have updates available.

The command is as follows:

$ yum list <available> <updates> <installed> <extras>
  • available—. This lists the available packages in the configured repositories.

  • updates—. This lists the available updates for currently installed packages.

  • installed—. This lists the packages currently installed on the system.

  • extras—. This lists the installed packages that are not present in any of the configured repositories.

So, if I wanted to find out which packages I have installed on my system, I would use the command yum list installed to return a detailed summary of packages installed and their version numbers. You can take this one step further and query for individual packages. You might want to find out which version of OpenOffice.org you have installed and which version is available for installation. For this, you would use yum list openoffice.org—the results of which would show you which version was installed and which version was available for updating.

yum can also search the headers and summaries for each RPM file so that you can find specific information about packages that would not usually be available in just the package name itself. For example, using yum search kdebindings would bring up entries matching kdebindings. The results of this command are shown here:

$ yum search kdebindings
Searching Packages:
Setting up Repo:  dries
Setting up Repo:  dag
Setting up Repo:  updates-released
Setting up Repo:  newrpms
Setting up Repo:  freshrpms
Setting up Repo:  base
Reading repository metadata in from local files
dries     : ################################################## 717/717
dag       : ################################################## 1808/1808
updates-re: ################################################## 722/722
newrpms   : ################################################## 385/385
freshrpms : ################################################## 477/477
base      : ################################################## 2622/2622


kdebindings.i386                         3.3.0-3                base
Matched from:
kdebindings


kdebindings-devel.i386                   3.3.0-3                base
Matched from:
kdebindings-devel
Development files for kdebindings
Development files for the KDE bindings.

Install kdebindings-devel if you want to develop non-KDE
applications that talk to KDE.


kdebindings.i386                         3.3.1-1                updates-released
Matched from:
kdebindings


kdebindings-devel.i386                   3.3.1-1                updates-released
Matched from:
kdebindings-devel
Development files for kdebindings
Development files for the KDE bindings.

Install kdebindings-devel if you want to develop non-KDE
applications that talk to KDE.



kdebindings-debuginfo.i386               3.3.1-1                updates-released
Matched from:
kdebindings-debuginfo
Debug information for package kdebindings
This package provides debug information for package kdebindings.
Debug information is useful when developing applications that use this
package or when debugging this package.

Configuring yum

As mentioned earlier, yum is primarily controlled by the contents of the yum.conf file and the /etc/yum.repos.d directory. Let’s take a closer look at the contents of both of these so you can get a better understanding of how best to configure yum.

When you initially install Fedora, there is a default yum.conf file that provides several switches for the yum command. It basically saves you from having to type in a number of switches and keeps yum simple. By default, yum is configured to do the following:

  • Keep a cache of headers in /var/cache/yum

  • Give minimal onscreen information during processing

  • Keep a log-file in /var/log/yum.log

  • Download only the most up-to-date packages

  • Be tolerant of errors in the process

  • Match packages to your processor architecture

  • Have a maximum retry limit of 20 times

  • Check for obsolete packages

  • Use GPG keys to ensure the identities of packages

All these options are contained within the yum.conf file, letting you easily modify or even remove certain lines. For instance, you might need yum to try only a maximum of five times, or you might need yum to give you more visual information.

You can add repository information into the yum.conf file, but as of Fedora Core 3, there has been a change in the way yum handles repositories. New to Fedora 3 was the yum.repos.d folder that allows you to create individual configuration files for each repository. By default, Fedora comes with repositories for their base packages, updated packages, updated packages that are in testing, and the more unstable development packages. Only the base and updated packages are enabled by default.

Caution

Unless you really know what you are doing, you should avoid the more unstable repositories of fedora-updates-testing and fedora-development. These repositories contain bleeding-edge packages that can break your system. You have been warned!

Opening a repository file shows you some details about the repository itself, including the path to it (either via HTTP, FTP, or local access), any lists of mirrors for that repository, whether that repository is enabled, and whether GPG checking is enabled.

If you want to add a new repository, you need to find out a few things before you can successfully add it to either its own repository file under /etc/yum.repos.d or in the yum.conf file.

You can also configure yum to ignore or exclude updates to certain packages. So, for instance, if you have a graphics driver that works only with a specific kernel version and you do not want to have to fix it every time a new kernel is released, you can elect for yum to exclude any kernel updates. Within the yum.conf file you need to add a line within the top section similar to this:

exclude=kernel

This tells yum to ignore any packages that start with kernel, and will hopefully limit the amount of repair work you have to do when a new kernel version is installed.

Creating a Local yum Repository

When yum is active, it can download a lot of information in the form of RPM headers and files, which can easily eat up bandwidth. If you have three or more Fedora-based machines on a local network, creating a local yum repository can be a good way to conserve bandwidth.

Before we start setting up the repository, you need to have the rsync and createrepo packages installed because you will need them both. Use the command yum install rsync createrepo to make sure that they are installed.

To begin, create a directory that will house your repository. In our example, we will use /home/andrew/repo/ as our target directory. Next, find the site you want to mirror (a selection of sites for the Fedora can be found at http://fedora.redhat.com/download/mirrors.html). For this example, we will use the UK Mirror service in Canterbury, Kent, which is rsync.mirror.ac.uk/fedora.redhat.com/updates/5/i386/.

rsync itself is easy to use as follows:

# rsync rsync://rsync.mirror.ac.uk/fedora.redhat.com/updates
/5/i386/*.rpm /home/andrew/repo

rsync then starts to download the files it finds within that directory to /home/andrew/repo. This can take some time (at the time of writing, there is about 5GB of updates available at the previous address). To ensure that rsync really is working, navigate using Nautilus to /home/andrew/repo; here you should see a number of packages appearing one after the other.

After you have completed downloading the updates you want, you need to create your repository. This is where the createrepo command comes in.

Using createrepo

createrepo is a program designed to quickly and efficiently draw the relevant information from a collection of rpm files to make the metadata yum requires to successfully install or update your currently installed package base.

The command is simply

createrepo /yourtargetdirectoryhere

So, if we were to use the example in the previous section, the syntax would look something like this:

$ createrepo /home/andrew/repo

This would give you the following output:

88/88 - alsa-lib-1.0.6-5.i386.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata

This shows that 88 RPMs were cataloged and that the relevant metadata was saved. The program automatically uses the given directory, so you do not have to worry about making several copies of directories.

After this is done, you are ready to include your new repository into the /etc/yum.conf file or into its own file under /etc/yum.repo.d. Let’s take a look at a typical configuration file for use with yum:

$ cat /etc/yum.repos.d/local.repo
[local]
name=Fedora Core $releasever - $basearch - Updates
baseurl=http://192.168.2.5/repo
enabled=1
gpgcheck=0

This file is fairly easy to read. Line one is the name of the repository that is passed to yum. The name must be enclosed in square brackets for it to be picked up; in this case, it is simply local. Line two gives us the display name for yum to show while it is busy working; for this repository, it uses Fedora Core $releasever - $basearch - Updates, which prints the release version (in this case 4) and the base architecture (i386). Next comes the base URL, or the primary download point. This is used for yum to scan and download the metadata it needs. The fourth line shows whether this repository is enabled: enabled=0 means it is disabled, and enabled=1 means it is enabled and able to be used. The final line determines whether the RPMs are checked using a GnuPG key. You are advised to obtain the relevant GnuPG key from the original repository to ensure that the packages you install have not been tampered with. This can then be imported into the RPM database by using the following command:

# rpm --import thiskey.txt

After the key has been imported into the database, yum can use it to verify that the packages are intact and safe to use.

Caution

Notice that we say the use of GPG keys can make packages safer to use. This is certainly true, but be aware that sometimes packages can conflict with each other. You should be careful about which repositories you use because some are incompatible with others. When selecting a repository, always read any FAQs for warnings of incompatibilities. Check out http://fedoraproject.org/wiki/Extras/RepositoryMixingProblems for the official Fedora stance on this.

Reference

http://www.linux.duke.edu/projects/yum/—The home page of the yum project, hosted at Linux@Duke (Duke University).

http://rpm.livna.org/—The Livna yum repository.

http://freshrpms.net/—The FreshMeat yum repository. It’s part of the OSTG, which also includes slashdot and linux.com.

http://dag.wieers.com—The yum repository of Dag Wieers.

http://atrpms.net—ATrpms yum repository. It includes some highly unstable packages, so use it at your own risk!

http://apt.sw.be/dries/—Dries’s yum/apt repository.

http://www.fedorafaq.org/—A useful, but unofficial, source of information. It gives locations of GPG keys for all the previously mentioned repositories.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.38