A Little About Linux: Package Management with RPM and YUM

One of the good things about Linux is the tools that it provides to manage software installation and removal.  There are two main ways to go about this management; RPM/YUM on Red Hat/CentOS/SUSE systems and DEB/APT-GET on Debian/Ubuntu/Mint systems.  This page describes the former system.

RPM originally stood for Red Hat Package Manager but now stands for RPM Packager Manager (one of the many recursive acronyms you'll see in Open Source software... probably because they think they're very clever) and is now pretty much universally known as the method of packaging, packages themselves and the management tool.

YUM on the other hand, standing for Yellowdog Updater Modified, manages the deployment, dependencies and updates of RPM packages and allows for searching and control of software repositories. 

Anatomy of an RPM file and Operations
The naming convention for an RPM file is;

rpmname-a.b.c-d.arch.rpm

rpmname - You may have gathered what this is, this is is the name of the application in the pavkage, although there are strange naming conventions just to keep you on your toes.  For instance, the Apache HTTP Server will normally be called 'httpd'... and these may be different on different Linux distributions.

a.b.c -  The package version number, this is normally the version of the program in the package.

d - The build or release number comes next, and this represents that minor changes made by the packager not the author of the code.

arch - This represents the architecture the package was built for, this could  be i386, i586, i686 and x86-64 depending on the binary, or this could be src if it is a source code package.

Some useful rpm commands and options;

Installs the httpd application, v adds verbosity and h prints hash marks to represent progress of the operation:
rpm -ivh httpd-2.2.15-31.el6.centos.x86_64.rpm

Updates the httpd application with an newer version, v adds verbosity and h prints hash marks to represent progress of the operation.  If there is no existing application, the operation reverts to a standard install:
rpm -Uvh httpd-2.2.15-32.el6.centos.x86_64.rpm

Uninstalls the package:
rpm -e httpd-2.2.15-32.el6.centos.x86_64

Query what package is installed:
rpm -q httpd

List all of the files in the installed package (Use -qlp if you need to find out the information about a currently un-installed package):
rpm -ql httpd

List all of the packages installed on the machine:
rpm -qa httpd

List the package a particular file was installed from:
rpm -qf /etc/httpd/conf

Show information about any installed package (Use -qip if you need to find out the information about a currently un-installed package):
rpm -qi httpd-2.2.15-31.el6.centos.x86_64

Getting Data out of an RPM
If you want to extract the contents of an RPM but don't want to install the contents on a machine, you're in luck, providing that you have SRC RPM package i.e. a source package.  You can use the cpio (Copy In and Out) and rpm2cpio commands.

First we need to pipe the contents of the RPM SRC file to CPIO;
rpm2cpio httpd-2.2.15-31.el6_5.src.rpm > httpd-2.2.15-31.el6_5.cpio

Now, once in the cpio format, the RPM file can be finally extracted;
cpio -i --make-directories < httpd-2.2.15-31.el6_5.cpio

Alternatively by using pipe '|' this can all be done in a one long command;
rpm2cpio httpd-2.2.15-31.el6_5.src.rpm | cpio -i --make-directories

Using YUM
So, YUM is known as a meta-packager as it allows the user to search and locate packages in multiple repositories on the Internet and locally and will also download and install them on the machine.  Some useful commands for YUM are shown below.

As an example to show YUM, we'll try and search for, install and then remove the Midnight Commander File Manager.

Search for a name, summary or description to find a specific package;
# yum search "midnight commander"

================= Matched: midnight commander ======================

mc.x86_64 : User-friendly text console file manager and visual shell

Find out more information about a specific package;
# yum info mc.x86_64

Available Packages
Name        : mc
Arch        : x86_64
Epoch       : 1
Version     : 4.7.0.2
Release     : 3.el6
Size        : 1.6 M
Repo        : base
Summary     : User-friendly text console file manager and visual shell
URL         : http://www.midnight-commander.org/
License     : GPLv2
Description : Midnight Commander is a visual shell much like a file manager, only
            : with many more features. It is a text mode application, but it also
            : includes mouse support. Midnight Commander's best features are its
            : ability to FTP, view tar and zip files, and to poke into RPMs for
            : specific files.

Find out the version of a package and the repository it is in;

# yum list mc.x86_64

Available Packages
mc.x86_64        1:4.7.0.2-3.el6          base

Install the specified package from a repository, also includes dependencies;
# yum install mc.x86_64

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mc.x86_64 1:4.7.0.2-3.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
============================================================================
 Package            Arch           Version             Repository      Size
============================================================================
Installing:
 mc                 x86_64         1:4.7.0.2-3.el6     base            1.6 M

Transaction Summary
============================================================================
Install       1 Package(s)

Total download size: 1.6 M
Installed size: 5.4 M
Is this ok [y/N]: y
Downloading Packages:
mc-4.7.0.2-3.el6.x86_64.rpm         1.6 MB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : 1:mc-4.7.0.2-3.el6.x86_64               1/1
  Verifying  : 1:mc-4.7.0.2-3.el6.x86_64               1/1

Installed:
  mc.x86_64 1:4.7.0.2-3.el6


Complete!

To check to see if there are any updates available;
# yum check-update

cpio.x86_64       2.10-12.el6_5              updates

Update a package to the latest version;
# yum update cpio.x86_64

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Update Process
Resolving Dependencies
--> Running transaction check
---> Package cpio.x86_64 0:2.10-11.el6_3 will be updated
---> Package cpio.x86_64 0:2.10-12.el6_5 will be an update
--> Finished Dependency Resolution

Dependencies Resolved
===================================================================================
 Package           Arch           Version         Repository           Size
===================================================================================
Updating:
 cpio              x86_64         2.10-12.el6_5   updates              192 k

Transaction Summary
===================================================================================
Upgrade       1 Package(s)

Total download size: 192 k
Is this ok [y/N]: y
Downloading Packages:
cpio-2.10-12.el6_5.x86_64.rpm                                                                                                                                            | 192 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : cpio-2.10-12.el6_5.x86_64          1/2
  Cleanup    : cpio-2.10-11.el6_3.x86_64          2/2
  Verifying  : cpio-2.10-12.el6_5.x86_64          1/2
  Verifying  : cpio-2.10-11.el6_3.x86_64          2/2

Updated:
  cpio.x86_64 0:2.10-12.el6_5

Complete!

Shows all of the dependencies of a specified package;
# yum deplist httpd

package: mc.x86_64 1:4.7.0.2-3.el6
  dependency: perl(File::Temp)
   provider: perl-File-Temp.noarch 0.22-1.el6.rf
   provider: perl.x86_64 4:5.10.1-136.el6
  dependency: libslang.so.2()(64bit)
   provider: slang.x86_64 2.2.1-1.el6
  dependency: perl(File::Basename)
   provider: perl.x86_64 4:5.10.1-136.el6
  dependency: perl(strict)
   provider: perl.x86_64 4:5.10.1-136.el6
  dependency: /usr/bin/perl
   provider: perl.x86_64 4:5.10.1-136.el6

Remove the specified package from the machine;
# yum erase mc

Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package mc.x86_64 1:4.7.0.2-3.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package        Arch             Version              Repository       Size
===================================================================================
Removing:
 mc             x86_64           1:4.7.0.2-3.el6       @base           5.4 M

Transaction Summary
===================================================================================
Remove        1 Package(s)

Installed size: 5.4 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing    : 1:mc-4.7.0.2-3.el6.x86_64                                                                                                                                                    1/1
  Verifying  : 1:mc-4.7.0.2-3.el6.x86_64                                                                                                                                                    1/1

Removed:
  mc.x86_64 1:4.7.0.2-3.el6

Complete!

Cleans the YUM cache directory;
# yum clean all

No comments: