Sunday, 17 April 2016

How to manage RPM packages ?


RPM command is used for installing, uninstalling, upgrading, querying, listing and checking RPM packages (with root privileges) on your Linux system.
RPM stands for Red Hat Package Manager.

1. Install a RPM package

RPM filename has package name, version, release and architecture name.
For example, the file : MySQL-client-3.23.57-1.i386.rpm
 Package Name : MySQL-client
 Version : 3.23.57
 Release : 1
 Architecture : i386

When you install a RPM,
  • checks whether your system is suitable for the software the RPM package contains.
  • figures out where to install the files located inside the rpm package.
  • installs them on your system.
  • adds that piece of software into its database of installed RPM packages.

Installs Mysql client package
# rpm -ivh MySQL-client-3.23.57-1.i386.rpm
Preparing...                ################################ [100%]
   1:MySQL-client           ################################ [100%]

Options
 -i : install a package
 -v : verbose
 -h : print hash marks as the package archive is unpacked.

You can also use dpkg on Debian, pkgadd on Solaris, depot on HP-UX to install packages.


2. Query the RPM packages

a. Query all the RPM packages
rpm -qa will query all the packages installed in your system.
# rpm -qa
cdrecord-2.01-10.7.el5
bluez-libs-3.7-1.1
setarch-2.0-1.1
. . .

Options
-q : query operation
-a : queries all installed packages

To identify whether a particular rpm package is installed on your system, combine rpm and grep command.
Example: It checks whether "cdrecord" package is installed on your system.
# rpm -qa | grep 'cdrecord'

b. Query a particular RPM package
After installation of a package to check the installation, you can query a particular package and verify.
# rpm -q MySQL-client
MySQL-client-3.23.57-1

# rpm -q MySQL
package MySQL is not installed

Note: To query a package, you should specify the exact package name.
If the package name is incorrect, then rpm command will report that the package is not installed.

c. Query RPM Packages in various format
The option –queryformat, which allows you to give the header tag names, to list the packages.
Enclose the header tag with in {}.
# rpm -qa --queryformat '%{name}-%{version}-%{release} %{size}\n'
cdrecord-2.01-10.7 12324
bluez-libs-3.7-1.1 5634
setarch-2.0-1.1 235563
 
d. Which RPM package does a file belong to ?
You have list of files and you would want to know which package owns all these files.
rpm -qf find the RPM package which is having the file /usr/bin/mysqlaccess :
# rpm -qf /usr/bin/mysqlaccess
MySQL-client-3.23.57-1

Options
 -f : file name


e. Locate documentation of a package that owns file
To know the list of documentations for a package that owns a file
rp -qdf gives the location of all the manual pages related to mysql package.
# rpm -qdf /usr/bin/mysqlaccess
/usr/share/man/man1/mysql.1.gz
/usr/share/man/man1/mysqlaccess.1.gz
/usr/share/man/man1/mysqladmin.1.gz
/usr/share/man/man1/mysqldump.1.gz
/usr/share/man/man1/mysqlshow.1.gz

Options
 -d : refers documentation


f. Get information about installed RPM package
# rpm -qi MySQL-client
Name        : MySQL-client   Relocations: (not relocatable)
Version     : 3.23.57        Vendor: MySQL AB
Release     : 1         Build Date: Wed 10 Jun 2002 11:08:28 PM CEST
Install Date: Mon 06 Feb 2014 03:19:16 AM PST  Build Host: build.mysql.com
Group       : Applications/Databases   Source RPM: MySQL-3.23.57-1.src.rpm
Size        : 5305109                  License: GPL / LGPL
Signature   : (none)
Packager    : Lenz Grimmer
URL         : http://www.mysql.com/
Summary     : MySQL - Client
Description : This package contains the standard MySQL clients.


To know RPM file information before installing it
# rpm -qip MySQL-client-3.23.57-1.i386.rpm
Name        : MySQL-client        Relocations: (not relocatable)
Version     : 3.23.57             Vendor: MySQL AB
Release     : 1        Build Date: Mon 09 Jun 2003 11:08:28 PM CEST
Install Date: (not installed)     Build Host: build.mysql.com
Group       : Applications/Databases  Source RPM: MySQL-3.23.57-1.src.rpm
Size        : 5305109                 License: GPL / LGPL
Signature   : (none)
Packager    : Lenz Grimmer
URL         : http://www.mysql.com/
Summary     : MySQL - Client
Description : This package contains the standard MySQL clients.


Options
 -i : view information about an rpm
 -p : specify a package name


g. List all the Files in a Package
It will list out the files without extracting into the local directory folder.
$ rpm -qlp ovpc-2.1.10.rpm
/usr/bin/mysqlaccess
/usr/bin/mysqldata
/usr/bin/mysqlperm
.
.
/usr/bin/mysqladmin

Options
 q : query the rpm file
 l : list the files in the package
 p : specify the package name

You can also extract files from RPM package using rpm2cpio.

h. List the dependency packages
To view the list of packages on which this package depends,
# rpm -qRp MySQL-client-3.23.57-1.i386.rpm
/bin/sh
/usr/bin/perl

i. Find out the state of files in a package
Finds the state (installed, replaced or normal) for all the files in a RPM package.
# rpm -qsp MySQL-client-3.23.57-1.i386.rpm
normal        /usr/bin/msql2mysql
normal        /usr/bin/mysql
normal        /usr/bin/mysql_find_rows
normal        /usr/bin/mysqlaccess
normal        /usr/bin/mysqladmin
normal        /usr/bin/mysqlbinlog
normal        /usr/bin/mysqlcheck
normal        /usr/bin/mysqldump
normal        /usr/bin/mysqlimport
normal        /usr/bin/mysqlshow
normal        /usr/share/man/man1/mysql.1.gz
normal        /usr/share/man/man1/mysqlaccess.1.gz
normal        /usr/share/man/man1/mysqladmin.1.gz


3. Verifying the RPM package

a. Verify a particular RPM package
It compares information about the installed files in the package with information about the files taken from the package metadata stored in the rpm database.
# rpm -Vp MySQL-client-3.23.57-1.i386.rpm
S.5....T c        /usr/bin/msql2mysql
S.5....T c        /usr/bin/mysql
S.5....T c        /usr/bin/mysql_find_rows
S.5....T c        /usr/bin/mysqlaccess

Options
 -V : verification
 -p : package name to verify

The character in the above output denotes : 
  file Size differs
  Mode differs (includes permissions and file type)
  MD5 sum differs
  Device major/minor number mismatch
  readlink(2) path mismatch
  User ownership differs
  Group ownership differs
  mTime differs


b. Verify a package owning file
It verifies the package which owns the given file name.
# rpm -Vf /usr/bin/mysqlaccess
S.5....T c /usr/bin/mysql


c. Verify all the RPM packages
# rpm -Va
S.5....T c /etc/issue
S.5....T c /etc/issue.net
S.5....T c /var/service/imap/ssl/seed
S.5....T c /home/httpd/html/horde/ingo/config/backends.php
.
.
S.5....T c /home/httpd/html/horde/ingo/config/prefs.php
S.5....T c /etc/printcap


4. Upgrading a RPM package

Upgrading a package is similar to installing one, but RPM automatically un-installs existing versions of the package before installing the new one.
If an old version of the package is not found, the upgrade option will still install it.

# rpm -Uvh MySQL-client-3.23.57-1.i386.rpm
Preparing...             ################################### [100%]
1:MySQL-client          ####################################



5. Uninstalling a RPM package

After uninstallation, you can query using rpm -qa and verify the uninstallation.
# rpm -ev MySQL-client

No comments:

Post a Comment

Note: only a member of this blog may post a comment.