Simple 14 Linux RPM Commands Frequently Used

RPM stands for RedHat Package Manager. It is used to Install, Update, Uninstall/Erase, Query, and Verify software packages in RedHat, CentOS, Suse, Fedora Linux systems.

The main query options are:
* Installation: -i or --install
* Upgrading: -U or --upgrade
* Uninstall/Erase: -e or --erase
* Querying: -q or --query
* Verifying: -V or --verify

Listed below are some commonly used RPM command examples.

1. Installing a package:
[root@centos55 tmp]# rpm -ivh perl-TimeDate-1.16-1.el5.centos.noarch.rpm
Preparing...                ########################################### [100%]
   1:perl-TimeDate          ########################################### [100%]
* Option -v: Verbose mode
* Option -h: Prints hash as the package archive is unpacked.

2. Installing a package while ignoring dependencies:
[root@centos55 tmp]# rpm -ivh perl-MailTools-1.77-1.el5.centos.noarch.rpm
error: Failed dependencies:
        perl(Date::Format) is needed by perl-MailTools-1.77-1.el5.centos.noarch
        perl(Date::Parse) is needed by perl-MailTools-1.77-1.el5.centos.noarch

[root@centos55 tmp]#  rpm -ivh --nodeps perl-MailTools-1.77-1.el5.centos.noarch.rpm
Preparing...                ########################################### [100%]
   1:perl-MailTools         ########################################### [100%]
* Option --nodeps: Don't do dependency check before installing or upgrading a package.

3. Query all installed packages:
[root@centos55 tmp]# rpm -qa
kernel-headers-2.6.18-194.el5
pciutils-devel-2.2.3-8.el5_4
gnome-backgrounds-2.15.92-1.fc6
zlib-1.2.3-3
cyrus-sasl-lib-2.1.22-5.el5_4.3
nspr-4.7.6-1.el5_4
libXau-1.0.1-3.1
tcp_wrappers-7.6-40.7.el5
libfontenc-1.0.2-2.2.el5
libieee1284-0.2.9-4.el5
perl-5.8.8-27.el5
....... {truncated}
* Option -a: all installed packages.
To query a particular package - use only -q and the exact package name.

4. Display/Query information about an installed package:
[root@centos55 tmp]# rpm -qi perl-MailTools-1.77-1.el5.centos
Name        : perl-MailTools               Relocations: (not relocatable)
Version     : 1.77                              Vendor: CentOS
Release     : 1.el5.centos                  Build Date: Wed 25 Jul 2007 08:43:51 PM IST
Install Date: Fri 28 Feb 2014 07:05:39 AM IST      Build Host: c5-x8664-build
Group       : Development/Libraries         Source RPM: perl-MailTools-1.77-1.el5.centos.src.rpm
Size        : 182210                           License: GPL or Artistic
Signature   : DSA/SHA1, Wed 25 Jul 2007 08:46:02 PM IST, Key ID a8a447dce8562897
Packager    : Johnny Hughes 
URL         : http://search.cpan.org/dist/MailTools/
Summary     : Various mail-related perl modules
Description :
MailTools is a set of Perl modules related to mail applications.
* Option -i: When used with -q will display package information.

5. Display/Query what package a particular file belongs:
[root@centos55 tmp]# rpm -qf /etc/samba/smbusers
samba-3.0.33-3.28.el5
In the above output the file "smbusers" belongs to package "samba-3.0.33-3.28.el5".
* Option -f: File name.

6. Display/Query list of configuration files for a package:
[root@centos55 tmp]# rpm -qc perl-5.8.8-27.el5
/usr/lib/perl5/5.8.8/Net/libnet.cfg
* Option -c: List configuration files.

7. List/Query all files of a package:
[root@centos55 tmp]# rpm -ql httpd-2.2.3-82.el5.centos
/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.d/README
/etc/httpd/conf.d/proxy_ajp.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/logs
..... {truncated}
* Option -l: List files in the package.

8. Query information about a RPM(not installed) with -p:
[root@centos55 tmp]# rpm -qip perl-TimeDate-1.16-1.el5.centos.noarch.rpm

[root@centos55 tmp]# rpm -qcp httpd-2.2.3-82.el5.centos.i386.rpm

[root@centos55 tmp]# rpm -qlp httpd-2.2.3-82.el5.centos.i386.rpm
* Option -p: query a (uninstalled)package name by specifying the .rpm file.

9. List/Query the Dependency of a Package with -R:
[root@centos55 tmp]# rpm -qR perl-MailTools
perl >= 0:5.002
perl(:MODULE_COMPAT_5.8.8)
perl(AutoLoader)
perl(Carp)
perl(Config)
perl(Date::Format)
perl(Date::Parse)
perl(Exporter)
.... {truncated}

10. List state of files of a package with -s:
[root@centos55 tmp]# rpm -qs perl-MailTools
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Address.pm
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Cap.pm
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Field
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Field.pm
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Field/AddrList.pm
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Field/Date.pm
normal        /usr/lib/perl5/vendor_perl/5.8.8/Mail/Filter.pm
.... {truncated}

11. List/Query all recently installed Packages:
[root@centos55 tmp]# rpm -qa --last

12. Verify a package:
[root@centos55 tmp]# rpm -Vp perl-MailTools-1.77-1.el5.centos.noarch.rpm
Unsatisfied dependencies for perl-MailTools-1.77-1.el5.centos.noarch: perl(Date::Format), perl(Date::Parse)

[root@centos55 tmp]# rpm -V samba-3.0.33-3.28.el5
S.5....T  c /etc/samba/smbusers
Note: Please refer here for the characters(S,T) in the above output.

13. Upgrade a package:
[root@centos55 tmp]# rpm -qa | grep "httpd-2.2*"
httpd-2.2.3-43.el5.centos

[root@centos55 tmp]# rpm -Uvh httpd-2.2.3-82.el5.centos.i386.rpm
Preparing...                ########################################### [100%]
   1:httpd                  ########################################### [100%]

[root@centos55 tmp]# rpm -qa | grep "httpd-2.2*"
httpd-2.2.3-82.el5.centos

14. Uninstall/Erase a package:
[root@centos55 tmp]# rpm -ev perl-TimeDate-1.16-1.el5.centos

No comments:

Post a Comment