YUM Tutorial : Package installer/remover for rpm systems

Evolution of YUM

yum is command line package management utility for Redhat like systems or more specifically Linux distributions which are based on RPM . Before RHEL 5 , rpm used to be package manager in Redhat like systems . But as Linux is becoming popular and more applications are coming in and also more and more people started using it , RPM started showing some limitations . One big issue is that RPM installation fails if the dependencies for a particular package are not installed on the system . Below is an example snippet of installing a package in Linux using RPM.

$ rpm -ivh Download/mplayer-1.0-71_snap20091017.fc11_92.i686.rpm
   warning: Download/mplayer-1.0-71_snap20091017.fc11_92.i686.rpm: Header  

   V4 DSA signature: NOKEY, key ID 66534c2b
    error: Failed dependencies:
    liba52.so.0 is needed by mplayer-4:1.0-71_snap20091017.fc11_92.i686
    libartsc.so.0 is needed by mplayer-4:1.0-71_snap20091017.fc11_92.i686



We can see that the package is dependent on some library , and the rpm installation fails as the dependent library is not there .In such a situation we need to identify the package which provides the library and need to install it . If there are many such dependencies on a single package, then it becomes cumbersome to identify so many packages and installing them . Because of these limitations , yum  evolved and it automatically takes care of such dependencies if the dependency is not installed on the system . We will see below how to use yum to install/remove/update packages and also various other features of yum .

yum repository
yum is based on online repositories which is simply a directory that holds several RPM packages and a repodata file list .We can also configure yum to use a local repository of packages . When we try to install a package using yum , it calls upon a single repository or several repositories for dependency resolution , fetch the RPMs , and install the required packages .  yum mostly accesses these directories or repositories over ftp/http We will  see later on another article how to create local repositories using createrepo. In this article , we will concentrate on yum commands

yum commands
yum provides options to install,remove and update packages. It can also be used to query for packages and also provides features to install all packages belonging to a particular group like Sound and Video , Editors etc. Let's now put yum in action.

$$ Installing Packages

To install a package using yum , simply use the following command. It will also install all the dependencies for the package
                  yum install "package-name"
                       e.g $ sudo yum install httpd

The above command after executing will identify all the dependencies and will prompt the user to press 'y' to install the package and dependencies. If the package is already installed , it will update the package. If we wish not to prompt us , then we can use the -y option
                   $ sudo yum -y install httpd
To install a package from a local directory
                       $ sudo yum localinstall  httpd-2.2.13-1.fc11.i586
Below is an example session of a yum command to install a package 
$ sudo yum install httpd
[sudo] password for aisha:
Loaded plugins: refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i586 0:2.2.13-1.fc11 set to be updated
--> Processing Dependency: httpd-tools = 2.2.13-1.fc11 for package: httpd-2.2.13-1.fc11.i586
--> Running transaction check
---> Package httpd-tools.i586 0:2.2.13-1.fc11 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved
============================================================================================================================================================
 Package                                Arch                            Version                                    Repository                          Size
============================================================================================================================================================
Updating:
 httpd                                  i586                            2.2.13-1.fc11                              updates                            1.1 M
Updating for dependencies:
 httpd-tools                            i586                            2.2.13-1.fc11                              updates                             71 k
Transaction Summary
============================================================================================================================================================
Install       0 Package(s)
Upgrade       2 Package(s)
Total download size: 1.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): httpd-2.2.13-1.fc11.i586.rpm                                                                                                  | 1.1 MB     00:38   
(2/2): httpd-tools-2.2.13-1.fc11.i586.rpm                                                                                            |  71 kB     00:01   
------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                        16 kB/s | 1.2 MB     01:15   
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : httpd-tools-2.2.13-1.fc11.i586                                                                                                       1/4
  Updating       : httpd-2.2.13-1.fc11.i586                                                                                                             2/4
  Cleanup        : httpd-tools-2.2.11-8.i586                                                                                                            3/4
  Cleanup        : httpd-2.2.11-8.i586                                                                                                                  4/4
Updated:
  httpd.i586 0:2.2.13-1.fc11                                                                                                                               
Dependency Updated:
  httpd-tools.i586 0:2.2.13-1.fc11                                                                                                                        

Complete!


$$ Updating packages
To update a particular package , we use the update option. Updating a package will fail if the package is not already installed.
              yum update "package-name"
                  e.g sudo  yum update mrtg
To update all the packages
             $ sudo yum -y update
To update all packages excluding specified package  
             yum -y --exclude=package-name

$$ Removing Packages
          yum remove "package-name"
             e.g $sudo  yum remove httpd


$$ Listing Packages
To display all the installed packages ( equivalent rpm -qa)
          $ yum list installed
e.g To check whether apache is installed or not , use 
           $ yum list installed httpd   (equivalent to rpm -q httpd)

To display all packages in the yum repositories that are  available to be installed.
           $ yum list available

To display  all packages with updates available in the yum repositories.

           $ yum list updates

To display all packages in all the repositories and all the packages
installed on your system
          $yum list 
To display package added to any enabled repository in the last seven(7) days.
         $yum list recent
To list all the updated packages
           $yum check-update


$$ Querying for Packages
To identify the package which provides the  dependency of a file
          yum provides  "file-name"
          e.g  yum provides /bin/ping
This options also supports wild card characters
        $ yum provides \*bin/ping

$$ Cleaning with yum
yum creates a cache of metadata and packages. It also creates or download some sqlite database files .This cache can take up a lot of space. The yum clean command allows you to clean up these files

To clean up any cached packages in any enabled repository cache directory.
          $ sudo yum clean packages
To clean up any xml metadata that may have been cached from any enabled repository
         $ sudo yum clean metadata
To clean up the cached copies of sqlite database files from any enabled repository cache.
         $ sudo yum clean dbcache
To clean all cached files from any enabled repository
         $ sudo yum clean all

$$ yum group commands

Groups in yum contains a list of packages which provides the same type of functionality . As for example group like "Sound And Video" contains package which provides some kind of multimedia features
To view all the available groups         
        $ sudo yum grouplist
To get the description and package list of a group
       $ sudo yum groupinfo "Sound and Video"
To install all packages from a group , use groupinstall option
        yum groupinstall "group-name" 
         e.g $sudo yum groupinstall "Sound and Video"
 
Conclusion:
Thus we had seen using yum to install and manage packages in Linux . Graphical interfaces like 
 yumex  are also available to manage package management through a graphical interface.



Comments

Subhasish said…
Dear Zaman,
please post the process of compiling vanilla Kernel downloaded from www. kernel.org. For Fedora and Redhat is easier to do the same using GUI tools provided with Distribution itself. :-)
Zaman said…
Hi Subhashish,

You can read my new post where I have written on compiling the Linux kernel from source.Hope it helps

Popular posts from this blog

PSSH : Parallel SSH to execute commands on a number of hosts

How to add check_http as a service in Nagios Monitoring using NRPE

Configuring Nagios to monitor services using NRPE