Yum Revisited (Part 2)
Here is the second article dedicated to the “yum” command. We will demonstrate some useful option of the command and how-to recover in some problematic situation. Keeping your system up to date is important, knowing how to do it and how to correct some issue related to rpm are also important. So let’s see if everyone can find something new about the “yum” command and see if we can apply it in our daily system admin job. You can also consult the “yum” website or the “yum” wiki to obtain more information. As always, I will try to make this article as useful as it can be, so we can all come back to it and use it as a reference to the “yum” command.
Checking if update are available
Let’s say you want to be advise when new update are available and want to be emailed with the list of packages included in the update. When we run the “yum” command with the “check-update” parameter, it actually go and check if any update are available at the repository you have defined in your “/etc/yum.repos.d” directory. If any update are available, they will be listed and the program exit code returned will be 100. If no update are available then the exit code will be 0.
# yum check-update ; echo $? Loaded plugins: changelog, fastestmirror, priorities Loading mirror speeds from cached hostfile * base: mirrors.portafixe.com * updates: mirrors.portafixe.com * addons: mirrors.portafixe.com * extras: mirrors.portafixe.com cman.i386 2.0.98-1.el5_3.7 updates ksh.i386 20080202-2.el5_3.1 updates openais.i386 0.80.3-22.el5_3.9 updates rgmanager.i386 2.0.46-1.el5.centos.4 updates tzdata.noarch 2009k-1.el5 updates 100 #
We can easily make a little script that we can put in our system crontab file, that will check if any update are available. If there are any, then a list of the updated package will be send to you by email
#!/bin/sh /usr/bin/yum check-update > /tmp/cu$$ 2>&1 RET=$? if [ $RET -eq 100 ]; then cat /tmp/cu$$ | mail -s "System Update Available" yourname@gmail.com fi rm /tmp/cu$$ > /dev/null 2>&1
Updating your system
To apply all the update available for your system, use the “yum update” command. Updated packages will be downloaded and then a confirmation will be ask before applying them. If you wish to download and install all the update without confirmation use “-y” parameter to skip the confirmation.
# yum -y update
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
* extras: mirrors.portafixe.com
* base: mirrors.portafixe.com
* updates: mirrors.portafixe.com
* addons: mirrors.portafixe.com
Setting up Update Process
No Packages marked for Update
#
Removing a package
To remove a package, simply specify the name of the package to be remove, using the “yum erase” command.
# yum erase bind
What RPM provide this file ?
Let’s say, you need a file, a library or a program and you are wondering what package is providing it. Well, there are two ways you can find what rpm include the file you are searching. If the file is already installed on your server and you want to know what package is supplying it, you can use the ” rpm” command to find it. But you have to specify the full path of the program in order to work. As an example, let’s say you want to know what package is supplying the “awk” program and that it is already installed on your server, you can use the instruction below.
# rpm -qf awk (Need to specify full path & must exist on your server) error: file /awk: No such file or directory # Must be on server & need to specify full path in order to find the rpm # type awk awk is /usr/bin/awk # rpm -qf /usr/bin/awk gawk-3.1.5-14.el5 #
But let’s say the file, program or library you are searching is not installed on your server. The rpm command will not be useful in that situation, this is when the ” yum” command can help us. In the example below, we are searching for the program “compress”. We will use the “yum” command with the “provides” option and then the “*/compress” parameters. By specifying the “*/compress”, we are telling “yum” to display matching file that end with ” compress” and that it could in any (*) directory. I am sure we will use this command often from now on, right ?
# yum provides */compress (We do not have to know where the program is or will be located) Loaded plugins: changelog, fastestmirror, priorities Loading mirror speeds from cached hostfile * base: centos.mirror.iweb.ca * updates: centos.mirror.iweb.ca * addons: centos.mirror.iweb.ca * extras: centos.mirror.iweb.ca ncompress-4.2.4-47.i386 : Fast compression and decompression utilities. Matched from: Filename : /usr/bin/compress #
Using yum to download package without installing them
There are situation when you only need to download the package without installing it. By using the option “–downloadonly” of the “yum install” command, we can do just that.
But first, we need to install the plugins “yum-downloadonly” to add that functionality to the “yum” command.
# yum install -y yum-downloadonly
After installing the plugin, when ever we need to download a package without installing it, we can use the “–downloadonly” option of the “yum install” command to do it. By default, the package will be downloaded in the directory “/var/cache/yum/base/packages”. If you need to download the package in a particular directory, you can specify it with the “–downloaddir” option (example below).
# yum install -y --downloadonly --downloaddir=/tmp zsh Loaded plugins: changelog, downloadonly, rhnplugin Setting up Install Process Parsing package install arguments Resolving Dependencies --> Running transaction check ---> Package zsh.i386 0:4.2.6-3.el5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================== Package Arch Version Repository Size ================================================================== Installing: zsh i386 4.2.6-3.el5 rhel-i386-server-5 1.7 M Transaction Summary ================================================================== Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s) Total size: 1.7 M Downloading Packages: exiting because --downloadonly specified # # ls -l /tmp/zsh* -rw-r--r-- 1 root root 1787914 May 6 11:31 /tmp/zsh-4.2.6-3.el5.i386.rpm #
Installing a local rpm and resolving dependencies
Let’s say you have a rpm package on your server that you want to install. You have tried to install it with the regular “rpm” install command, but the package have some rpm dependencies that you do not have. You can then use the “yum localinstall” command to install your package and let “yum” try to resolve these dependencies. For example, we have a package named “shutter”, we cannot install it with the regular rpm command because it has a lot of dependencies. Below, we use to “yum localinstall” to resolve them. The example below represent only a partial screen output.
# ls -l shutter-0.70.1-1.ppa2.fc10.noarch.rpm -rw-rw-r-- 1 jacques jacques 780953 Sep 19 12:02 shutter-0.70.1-1.ppa2.fc10.noarch.rpm # # yum localinstall shutter-0.70.1-1.ppa2.fc10.noarch.rpm Loaded plugins: downloadonly, fastestmirror Setting up Local Package Process Examining shutter-0.70.1-1.ppa2.fc10.noarch.rpm: shutter-0.70.1-1.ppa2.fc10.noarch Marking shutter-0.70.1-1.ppa2.fc10.noarch.rpm to be installed Loading mirror speeds from cached hostfile * extras: mirrors.portafixe.com * base: mirrors.portafixe.com * updates: mirrors.portafixe.com * addons: mirrors.portafixe.com Resolving Dependencies --> Running transaction check ---> Package shutter.noarch 0:0.70.1-1.ppa2.fc10 set to be updated --> Processing Dependency: gnome-web-photo for package: shutter --> Processing Dependency: gtklp for package: shutter --> Processing Dependency: perl(Gnome2) for package: shutter --> Processing Dependency: perl(Gnome2::Canvas) for package: shutter --> Processing Dependency: perl(Gnome2::GConf) for package: shutter --> Processing Dependency: perl(Gnome2::VFS) for package: shutter --> Processing Dependency: perl(Gnome2::Wnck) for package: shutter --> Processing Dependency: perl(Goo::Canvas) for package: shutter --> Processing Dependency: perl(Gtk2) for package: shutter .... ....
Listing packages
With the “list” parameter as you can guess, we will obtain a list of the packages available. With no parameter, the “list” will list all packages available. On the last column displayed, we will notice that it will informed us if the package is actually installed or there is an update for it and if it is not installed it will display the repository that offer the package.
root@rhel5:~# yum list | grep -i openssh or yum list openssh* openssh.i386 4.3p2-29.el5 installed openssh-askpass.i386 4.3p2-29.el5 installed openssh-clients.i386 4.3p2-29.el5 installed openssh-server.i386 4.3p2-29.el5 installed root@rhel5:~# yum list | grep -i openswan openswan.i386 2.6.14-1.el5_3.3 updates openswan-doc.i386 2.6.14-1.el5_3.3 updates root@rhel5:~# yum list | grep -i openvpn NetworkManager-openvpn.i386 1:0.7.0-18.svn11.el5.1 epel openvpn.i386 2.1-0.29.rc15.el5 epel openvpn-auth-ldap.i386 2.0.3-3.el5 epel root@rhel5:~#
Search for pattern in all packages name, description and summary
The search option checks the names, descriptions, summaries and listed package maintainers of all of the available packages to find those that match. For example, to search for all packages that relate to “zip”, type:
# yum search zip
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
* extras: mirrors.portafixe.com
* base: mirrors.portafixe.com
* updates: mirrors.portafixe.com
* addons: mirrors.portafixe.com
======================= Matched: zip =================================================
mc.i386 : User-friendly text console file manager and visual shell
kdeutils.i386 : K Desktop Environment - Utilities
bzip2.i386 : A file compression utility.
bzip2-devel.i386 : Header files and libraries for developing apps which will use bzip2.
bzip2-libs.i386 : Libraries for applications using bzip2
eject.i386 : A program that ejects removable media using software control.
gzip.i386 : The GNU data compression program.
java-1.4.2-gcj-compat-src.i386 : Source files for libgcj
libgsf.i386 : GNOME Structured File library
mikmod.i386 : A MOD music file player.
mono-core.i386 : The Mono CIL runtime, suitable for running .NET code
ncompress.i386 : Fast compression and decompression utilities.
perl-Archive-Tar.noarch : A module for Perl manipulation of .tar files
perl-Archive-Zip.noarch : Perl library for accessing Zip archives
perl-Compress-Zlib.i386 : A module providing Perl interfaces to the zlib compression library.
perl-String-CRC32.i386 : Perl interface for cyclic redundency check generation
rar.i386 : RAR archiver to create and manage RAR archives
unzip.i386 : A utility for unpacking zip files.
xarchiver.i386 : Archive manager for Xfce
zip.i386 : A file compression and packaging utility compatible with PKZIP.
zlib.i386 : The zlib compression and decompression library.
zlib-devel.i386 : Header files and libraries for Zlib development.
[root@boris packages]
#
We can use any of the standard wildcard characters to run any search option with a partial word or name: ? to represent any one character, and * to mean zero or more characters. Always add the escape character (\) before wildcards.
Getting information about a package
The “info” parameter allow you to display information about the package you specified.
# yum info python
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
* extras: mirrors.portafixe.com
* base: mirrors.portafixe.com
* updates: mirrors.portafixe.com
* addons: mirrors.portafixe.com
Installed Packages
Name : python
Arch : i386
Version : 2.4.3
Release : 24.el5_3.6
Size : 21 M
Repo : installed
Summary : An interpreted, interactive, object-oriented programming language.
URL : http://www.python.org/
License : PSF - see LICENSE
Description:
Python is an interpreted, interactive, object-oriented programming language often compared to Tcl, Perl, Scheme or Java. Python
includes modules, classes, exceptions, very high level dynamic data types and dynamic typing. Python supports interfaces to many
system calls and libraries, as well as to various windowing systems (X11, Motif, Tk, Mac and MFC). Programmers can write new
built-in modules for Python in C or C++. Python can be used as an extension language for applications that need a programmable
interface. This package contains most of the standard Python modules, as well as modules for interfacing to the Tix widget set for
Tk and RPM. Note that documentation for Python is provided in the python-docs package.
#
Correcting yum operation error
You may sometime encounter situation when trying to update your system, you keep getting error. This can occur, when download have been have been terminated abnormally. The first thing we should do in that situation is to run the “yum clean all” command. This will clear the yum cache directory (/var/cache/yum) and most of the time it resolve the problem.
# yum clean all
Loaded plugins: downloadonly, fastestmirror
Cleaning up Everything
Cleaning up list of fastest mirrors
#
Listing package group
This “grouplist” option, list the package group that are installed on your server and that are available for you to download. The example below was run on a Centos 5 server, on a Redhat server some package group may not show. Centos have more package group than Red hat. The list have also been shortened, to take less space on this page.
# yum grouplist Installed Groups: Administration Tools DNS Name Server FTP Server Mail Server Multimedia MySQL Database ... Text-based Internet Web Server Windows File Server X Software Development X Window System Available Groups: Development Tools GNOME Software Development ... News Server Web Development Window Managers Done #
Getting information about a package group
The “groupinfo” option of the “yum” command display the list the packages that are part of the specified group. The “Default Packages” section, list the packaged that will be installed when that group is install. The “Mandatory” section, list packages that requires to be installed for the package group to work. Depending on the group you specify, there may be a “Optional Packages” section in the list, these packages are the part of the group but won’t be install by default, you will need to install them one by one should you require one of them.
# yum groupinfo Graphics"
[root@boris ~]# yum groupinfo "DNS Name Server"
Loaded plugins: downloadonly, fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
* extras: centos.mirror.iweb.ca
* base: centos.mirror.iweb.ca
* updates: centos.mirror.iweb.ca
* addons: centos.mirror.iweb.ca
Group: DNS Name Server
Description: This package group allows you to run a DNS name server (BIND) on the system.
Mandatory Packages:
bind
Default Packages:
bind-chroot
#
Installing a package group
As you may already guess, the “groupinstall” option allow you to install the default (and required if needed) of the specified group. In the example below, we have install the “DNS Name Server” group.
root@anemone:/# yum groupinstall "DNS Name Server"
Package 30:bind-9.3.4-10.P1.el5_3.3.i386 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package bind-chroot.i386 30:9.3.4-10.P1.el5_3.3 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
===============================================
Package Arch Version
===============================================
Installing:
bind-chroot i386 30:9.3.4-10.P1.el5_3.3
Transaction Summary
===============================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)
Total download size: 42 k
Is this ok [y/N]: y
Downloading Packages:
bind-chroot-9.3.4-10.P1.el5_3.3.i386.rpm | 42 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : bind-chroot [1/1]
Installed: bind-chroot.i386 30:9.3.4-10.P1.el5_3.3
Complete!
#

Recent Comments