The yum command makes it easy to add and remove software packages to your system. It maintains a database regarding the proper way to add, upgrade, and remove packages. This makes it relatively simple to add and remove software with a single command.
If you want to know all that you can do with yum, run the command by itself:
# yum Loading "rhnplugin" plugin Loading "installonlyn" plugin You need to give some command usage: yum [options] < grouplist, localinstall, groupinfo, localupdate, resolvedep, erase, deplist, groupremove, makecache, upgrade, provides, shell, install, whatprovides, groupinstall, update, groupupdate, info, search, check-update, list, remove, clean, grouperase > options: -h, --help show this help message and exit -t, --tolerant be tolerant of errors -C run entirely from cache, don't update cache -c [config file] config file location -R [minutes] maximum command wait time -d [debug level] debugging output level -e [error level] error output level -y answer yes for all questions --version show Yum version and exit --installroot=[path] set install root --enablerepo=[repo] enable one or more repositories (wildcards allowed) --disablerepo=[repo] disable one or more repositories (wildcards allowed) -x [package], --exclude=[package] exclude package(s) by name or glob --obsoletes enable obsoletes processing during updates --noplugins disable Yum plugins
You'll examine how a few of these options work in the following sections. While it's unlikely that you'll have an Internet connection during the exam, you could have a network connection to a local repository. So you should be ready to use the yum command during either Red Hat exam. Besides, it's an excellent tool for administering Red Hat systems.
|On the Job|| |
If you run the yum command as a regular user, you'll get a message to the effect that the local system is not registered on the RHN (even if you've already done so). The only way to use yum is through the administrative (root) account.
The basic yum configuration is shown in /etc/yum.conf. The first line shows that it's the main configuration file for this service:
The cachedir directive specifies the directory where yum downloads are stored:
If you change the keepcache setting, you can save downloaded RPMs in a /var/ cache/yum subdirectory associated with the RHN software channel or repository:
The debuglevel directive specifies the level of messages specified in the file associated with the logfile directive. Since multiple packages may be associated with each version of RHEL, the pkgpolicy directive specifies that yum uses the latest version:
debuglevel=2 logfile=/var/log/yum.log pkgpolicy=newest
The distroverpkg directive shown takes the version number from the /etc/redhat-release file:
The tolerant directive shown allows yum to work even with minor errors. For example, if you run yum install on a list of packages, and one is already installed, the command still proceeds.
Most Linux distributions are architecture-dependent; the following directive makes sure that yum downloads correspond to your CPU architecture:
During a yum update command, the following directive checks for and uninstalls any obsolete packages:
Naturally, to confirm appropriate packages, it's important for yum to check the GPG key, as determined by the following directive:
The following directive includes plug-ins as defined in the /etc/yum/pluginconf.d/ and /usr/lib/yum-plugins/ directories as part of the yum configuration:
To make sure the header data downloaded from the RHN (and any other repositories) are up to date, the metadata_expire directive specifies a lifetime for headers. In other words, if you haven't used the yum command in 30 minutes (1800 seconds), the next use of the yum command downloads the latest header information.
Finally, the following notes the default location for configuring other repositories. Even though it's in comments, the /etc/yum.repos.d directory is the default location for these third-party repository configuration files.
# PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d
Regular RHN repositories are defined in various python-based configuration files in the /usr/lib/yum-plugins directory.
There are two basic installation commands. If you haven't installed a package before, or if you want to update it to the latest stable version, run the yum install packagename command. For example, if you're checking for the latest version of the Samba RPM, the following command will update it or add it if it isn't already installed on your system.
# yum install samba
If you just want to keep the packages on your system up to date, run the yum update packagename command. For example, if you already have the Samba RPM installed, the following command makes sure it's updated to the latest version:
# yum update samba
If you haven't installed Samba, this command doesn't add it to your installed packages.
The yum update command by itself is powerful; if you want to make sure that all installed packages are updated to the latest stable versions, run the following command:
# yum update
The yum update command may take some time as it communicates with the RHN, with all dependencies.
But what if you don't know what you want to install? For example, if you want to install the Evince document reader, the yum whatprovides filename command can help. To search for all instances of the Evince document reader, you can run the following command:
# yum whatprovides evince
It lists all instances of the evince file name, with the associated RPM package. It works like the locate command; in other words, partial file names also work with the yum whatprovides command. Once you identify the package you need to install, you can proceed with the yum install packagename command.
|On the Job|| |
If you have problems with yum, try yum clean all. If there are recent updates to RHN packages (or third-party repositories), this command flushes the current cache of headers, allowing you to resynchronize headers with configured repositories, without having to wait the default 30 minutes before the cache is automatically flushed (as defined by the metadata_expire directive in /etc/yum.conf).
Red Hat maintains a public list of errata at http://rhn.redhat.com/errata/. It's divided by RHEL versions and now by repositories. If you have an RHEL subscription, you generally don't need to watch this, as long as you keep your packages up to date using Pup or by running periodic yum update commands. This list is useful for those third parties who use RHEL source code, such as CentOS, Scientific Linux, or even the new Oracle Linux.
To add third-party repositories to your system, you'll need to add appropriate directives to a .repo file in the /etc/yum.repos.d directory. For example, I often use Axel Thimm's third-party repository for my RHEL and Fedora Core systems. It's available from http://ATrpms.net. To make it work with my RHEL system, I use the instructions available from that Web site and add the following information to atrpms.repo in the /etc/yum .repos.d/ directory:
[atrpms] baseurl=http://dl.atrpms.net/el5-i386/atrpms/stable gpgkey=http://atrpms.net/RPM-GPG-KEY.atrpms gpgcheck=1
If you want to disable any repository in the /etc/yum.repos.d/ directory, add the following directive to the applicable repository file:
You can update packages with a graphical tool. The pirut tool, also known as the Package Manager utility, has several advantages: It includes an interface similar to the Anaconda Custom Installation screen. It allows you to install more than one package at a time. It automatically installs any other dependent packages that may be needed.
There are two ways to start the Package Manager utility. From the GNOME desktop, choose Applications | Add/Remove Software. Alternatively, in a GUI text command window, run the pirut command. Either action opens the Package Manager shown in Figure 5-2. (If you're running RHEL 5 and haven't registered this system, or have trouble with your Internet connection, the windows in the Browse tab will be blank.)
Figure 5-2: The Package Manager
You can use the Package Manager to add the packages or package groups of your choice. As you can see in Figure 5-2, there are three tabs. The Browse tab displays package groups in a format similar to what you saw during the GUI installation process.
The Search tab allows you to search for a specific package and identify whether or not it's currently installed. When you search, partial matches are okay; for example, a search for system-config returns all packages associated with system-config-* tools.
The List tab lists all packages; they can be filtered by installed and available packages.
Exercise 5-1: Installing More with pirut
This exercise requires a network connection to a remote repository. If you're using a rebuild of RHEL 5, you'll need to make sure your connection to the core repository for your rebuild is working. If you've already connected to the RHN, you can skip a couple of steps in this exercise.
Run the yum list command. If you're properly connected to a repository, you'll see a full list of available packages, including those already installed. Note the label in the right column; it will either show the repository where a package is available or note that the package is already installed.
Try the pirut command in a GUI; alternatively, in GNOME, choose Applications (or in KDE, choose Main Menu | System) | Add / Remove Software. It's more informative if you start pirut from a GUI command line, as errors are shown in the command line terminal.
Under the Browse tab, you'll see the same package groups that you saw in Chapter 2 if you customized the packages to be installed.
Review available package groups on the Browse tab. Select an active package group, and click Optional Packages. For this exercise, select a package of your choice, which will be installed when you click Apply.
Click the List tab. Review the list of available packages. Packages that are already selected are currently installed. If you select or deselect a package, it will be installed or removed (with dependencies) when you click Apply.
Click the Search tab. Use a common search term such as gnome and watch as a long list of packages are shown. Use a less common search term such as iptables. Highlight a package and review it in the Package Details window.
Once you've selected some packages, click Apply. You'll see a window with a list of packages that you've selected for installation and removal. Click Continue.
If there are dependencies, you'll see a Dependencies Added window that lists those dependent packages that will also be installed or removed. Review the Details, and click Continue.
Wait as pirut downloads packages to be installed.
When the process is complete, you'll see a confirmation. Click OK, and then choose File | Quit to exit pirut.