All about RPM ( redhat Package Manager) HowTos

How can I list the contents of an uninstalled rpm

To list the contents. find out what dependencies a rpm file has:

$ rpm -qpR [.rpm-file]

$ rpm -qR [package-name]

The RPM package manager rpm comes with various utilities to interact with packages. The following command will list all the files inside an RPM package:

$ rpm -qlp ./path/to/test.rpm

For example:

$ rpm -qlpv ./packagecloud-test-1.1-1.x86_64.rpm

-rwxr-xr-x   1   root    root    8286 Jul 16  2014 /usr/local/bin/packagecloud_hello

$ rpm -qpR [.rpm-file]

Extract cpio archive from RPM packages

o extract files from an RPM package you must first extract a cpio archive from the package itself. RedHat provides a utility called rpm2cpio which does exactly that:

$ rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm

Extract files from an RPM package’s cpio archive

The rpm2cpio command will output (to stdout) a cpio archive from the RPM package. To extract the package files we’ll use the output from rpm2cpio and then use the cpio command to extract and create the files we need.

For example:

$ rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm | cpio -idmv
./usr/local/bin/packagecloud_hello
17 blocks

The cpio command copies files to and from archives. In the example above, we use cpio with the -i flag to extract the files from the archive, -d to create the leading directories where needed, and -m to preserve the file modification times when creating files. The -v flag (verbose) is to list the files processed for the sake of this example.

The result of our previous example is the creation of a ./usr/ folder in our working directory containing the files from the RPM package packagecloud-test-1.1-1.x86_64.rpm.

$ file usr/local/bin/packagecloud_hello

usr/local/bin/packagecloud_hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x77fe4f2fa02ee973bf4d74867729e950fcde7107, not stripped

Uninstalling a RPM Package

You can use either the rpm or yum command to remove RPM packages. Note that removing a package does not damage the Advanced Server data directory. Uninstalling a RPM Package with rpm Include the -e option on the rpm command to remove installed packages; the command syntax is: rpm -e package_name[package_name...] Where the package_name is the name of the package that you would like to remove. The package name is the name of the .rpm file used when installing the package, with the version number and file extension (.rpm) removed; for example, the command:
#rpm -e fail2ban-firewalld-0.9.7-1.el7.noarch.rpm
Removes the package installed with the command:
#rpm -i fail2ban-firewalld-0.9.7-1.el7.noarch.rpm 
To instruct rpm to remove multiple packages, provide a list of packages you wish to remove when invoking the command.
Uninstalling a RPM Package with yum
You can use the yum remove command to remove an RPM package. To remove a package, open a terminal window, assume superuser privileges, and enter the command:
#yum remove package_name
Where package_name is the name of the package that you would like to remove. The package name is the name of the .rpm file used when installing the package, with the file extension (.rpm) removed;
for example, the command:
#yum remove fail2ban-firewalld-0.9.7-1.el7.noarch.rpm
Removes the package installed with the command:
#yum install fail2ban-firewalld-0.9.7-1.el7.noarch.rpm
Note: yum and RPM will not remove a package that is required by another package. If you attempt to remove a package that satisfies a package dependency, yum or RPM will provide a warning.

RPM Trivia:

Did you know that RPM was originally written in 1997 by Erik Troan and Marc Ewing

When did Yum appear in Red Hat?

Answer: Yum which now ubiquitous in Red Hat did not appear in Red Hat until RHEL5 was released.

 

The rpm  command enables you to get much information about packages. Using RPM queries can be a really useful way to find out how software can be configured and used. To start, you can use the rpm -qa  command. Like yum list installed, this command shows a list of all software that is installed on the machine. Use grep  on this command to find out specific package names. To perform queries on RPM packages, you just need the name and not the version information.

After finding the package about which you want to have more information, you can start with some generic queries to find out what is in the package. In the following examples, I assume that you are using RPM queries on the nmap RPM package. To start, type rpm -qi nmap  to get a description of the package.

The next step is to use rpm -ql nmap, which shows a list of all files that are in the package nmap. On some packages, the result can be a really long list of filenames that is not particularly useful.

To get more specific information, you can use

  • rpm -qd nmap, which shows all documentation available for the package,
  • rpm -qc nmap, which shows all configuration files in the package.

Using RPM queries can really help in finding out more useful information about packages. The only thing that you need to know is the RPM package name a specific file belongs to.

To find this, use

rpm -qf <filename>

the filename should be specified with path, for examle /bin/ls. So you should us e rpm -qf /bin/ls  not rpm -qf ls   to find the name of the RPM the ls  command comes from.

How to check dependencies of RPM Package before Installing

Let’s say you would like to do a dependency check before installing or upgrading a package that is residing on you local filesystem. For example, use the following command to check the dependencies of package. It will display the list of dependencies of package. You have package tree in you /root directory you can use:

# rpm -qpR tree*
RPM command and options
  1. -q : Query a package
  2. -p : List capabilities this package provides.
  3. -R: List capabilities on which this package depends..

How to Install a RPM Package Without Dependencies

If you know that all needed packages are already installed or that package will work with older libraries that are already installed you can ignore those dependencies by using the option –nodeps (no dependencies check) before installing the package.

[root@ronserver]# rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm

Preparing...                ########################################### [100%]
   1:BitTorrent             ########################################### [100%]

The above command forcefully install rpm package by ignoring dependencies errors, but if those dependency files are missing, then the program will not work at all, until you install them.

How to check if a package is installed

Using -q option with package name, will show whether an rpm installed or not.

[root@ronserver]# rpm -q BitTorrent

BitTorrent-5.2.2-1.noarch

How to List Recently Installed RPM Packages

Use the following rpm command with -qa (query all) option, will list all the recently installed rpm packages.

[root@ronserver]# rpm -qa --last

BitTorrent-5.2.2-1.noarch                     Tue 04 Dec 2012 05:14:06 PM BDT
pidgin-2.7.9-5.el6.2.i686                     Tue 04 Dec 2012 05:13:51 PM BDT
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686       Tue 04 Dec 2012 04:43:06 PM BDT
cyrus-sasl-2.1.23-13.el6_3.1.i686             Tue 04 Dec 2012 04:43:05 PM BDT
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686         Tue 04 Dec 2012 04:43:04 PM BDT
cyrus-sasl-plain-2.1.23-13.el6_3.1.i686       Tue 04 Dec 2012 04:43:03 PM BDT

How to Upgrade a RPM Package

If we want to upgrade any RPM package “–U” (upgrade) option will be used. One of the major advantages of using this option is that it will not only upgrade the latest version of any package, but it will also maintain the backup of the older package so that in case if the newer upgraded package does not run the previously installed package can be used again.

[root@ronserver]# rpm -Uvh nx-3.5.0-2.el6.centos.i686.rpm
Preparing...                ########################################### [100%]
   1:nx                     ########################################### [100%]

How to Remove a RPM Package

To un-install an RPM package, for example we use the package name nx, not the original package name nx-3.5.0-2.el6.centos.i686.rpm. The -e (erase) option is used to remove package.

[root@ronserver]# rpm -evv nx

How to Remove an RPM Package Without Dependencies

The –nodeps (Do not check dependencies) option forcefully remove the rpm package from the system. But keep in mind removing particular package may break other working applications.

[root@ronserver]# rpm -ev --nodeps vsftpd

How to Query a file that belongs which RPM Package

Let’s say, you have list of files and you would like to find out which package belongs to these files. For example, the following command with -qf (query file) option will show you a file /usr/bin/htpasswd is own by package httpd-tools-2.2.15-15.el6.centos.1.i686.

[root@ronserver]# rpm -qf /usr/bin/htpasswd

httpd-tools-2.2.15-15.el6.centos.1.i686

How to Query a Information of Installed RPM Package

Let’s say you have installed an rpm package and want to know the information about the package. The following -qi (query info) option will print the available information of the installed package.

[root@ronserver]# rpm -qi vsftpd

Name        : vsftpd				   Relocations: (not relocatable)
Version     : 2.2.2				   Vendor: CentOS
Release     : 11.el6				   Build Date: Fri 22 Jun 2012 01:54:24 PM BDT
Install Date: Mon 17 Sep 2012 07:55:28 PM BDT      Build Host: c6b8.bsys.dev.centos.org
Group       : System Environment/Daemons           Source RPM: vsftpd-2.2.2-11.el6.src.rpm
Size        : 351932                               License: GPLv2 with exceptions
Signature   : RSA/SHA1, Mon 25 Jun 2012 04:07:34 AM BDT, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://vsftpd.beasts.org/
Summary     : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.

Get the Information of RPM Package Before Installing

If you want know the information about this package before installing use -qi (query info package) will print the information of a package sqlbuddy.

# rpm -qip tree

How to Query documentation of Installed RPM Package

To get the list of available documentation of an installed package, use the following command with option -qdf (query document file) will display the manual pages related to vmstat package.

[root@ronserver]# rpm -qdf /usr/bin/vmstat

/usr/share/doc/procps-3.2.8/BUGS
/usr/share/doc/procps-3.2.8/COPYING
/usr/share/doc/procps-3.2.8/COPYING.LIB
/usr/share/doc/procps-3.2.8/FAQ
/usr/share/doc/procps-3.2.8/NEWS
/usr/share/doc/procps-3.2.8/TODO

How to Verify a RPM Package

Verifying a package compares information of installed files of the package against the rpm database. The -Vp (verify package) is used to verify a package.

[root@ronserver downloads]# rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm

S.5....T.  c /etc/httpd/conf.d/sqlbuddy.conf

How to Verify all RPM Packages

Type the following command to verify all the installed rpm packages.

[root@ronserver]# rpm -Va

S.5....T.  c /etc/rc.d/rc.local
.......T.  c /etc/dnsmasq.conf
.......T.    /etc/ld.so.conf.d/kernel-2.6.32-279.5.2.el6.i686.conf
S.5....T.  c /etc/yum.conf
S.5....T.  c /etc/yum.repos.d/epel.repo

How To rebuild Corrupted RPM Database

Sometimes rpm database gets corrupted and stops all the functionality of rpm and other applications on the system. So, at the time we need to rebuild the rpm database and restore it with the help of following command.

[root@ronserver]# cd /var/lib
[root@ronserver]# rm __db*
[root@ronserver]# rpm --rebuilddb
[root@ronserver]# rpmdb_verify Packages

Options

root@ronserver:~ # rpm --help
Usage: rpm [OPTION...]
Query/Verify package selection options:
  -a, --all                        query/verify all packages
  -f, --file                       query/verify package(s) owning file
  -g, --group                      query/verify package(s) in group
  -p, --package                    query/verify a package file
  --pkgid                          query/verify package(s) with package identifier
  --hdrid                          query/verify package(s) with header identifier
  --triggeredby                    query the package(s) triggered by the package
  --whatrequires                   query/verify the package(s) which require a dependency
  --whatprovides                   query/verify the package(s) which provide a dependency
  --nomanifest                     do not process non-package files as manifests

Query options (with -q or --query):
  -c, --configfiles                list all configuration files
  -d, --docfiles                   list all documentation files
  -L, --licensefiles               list all license files
  --dump                           dump basic file information
  -l, --list                       list files in package
  --queryformat=QUERYFORMAT        use the following query format
  -s, --state                      display the states of the listed files

Verify options (with -V or --verify):
  --nofiledigest                   don't verify digest of files
  --nofiles                        don't verify files in package
  --nodeps                         don't verify package dependencies
  --noscript                       don't execute verify script(s)

Install/Upgrade/Erase options:
  --allfiles                       install all files, even configurations which might
                                   otherwise be skipped
  --allmatches                     remove all packages which match  (normally an
                                   error is generated if  specified multiple
                                   packages)
  --badreloc                       relocate files in non-relocatable package
  -e, --erase=+           erase (uninstall) package
  --excludedocs                    do not install documentation
  --excludepath=             skip files with leading component 
  --force                          short hand for --replacepkgs --replacefiles
  -F, --freshen=+     upgrade package(s) if already installed
  -h, --hash                       print hash marks as package installs (good with -v)
  --ignorearch                     don't verify package architecture
  --ignoreos                       don't verify package operating system
  --ignoresize                     don't check disk space before installing
  -i, --install                    install package(s)
  --justdb                         update the database, but do not modify the filesystem
  --nodeps                         do not verify package dependencies
  --nofiledigest                   don't verify digest of files
  --nocontexts                     don't install file security contexts
  --noorder                        do not reorder package installation to satisfy
                                   dependencies
  --noscripts                      do not execute package scriptlet(s)
  --notriggers                     do not execute any scriptlet(s) triggered by this package
  --nocollections                  do not perform any collection actions
  --oldpackage                     upgrade to an old version of the package (--force on
                                   upgrades does this automatically)
  --percent                        print percentages as package installs
  --prefix=<dir>                   relocate the package to <dir>, if relocatable
  --relocate=<old>=<new>           relocate files from path <old> to <new>
  --replacefiles                   ignore file conflicts between packages
  --replacepkgs                    reinstall if the package is already present
  --test                           don't install, but tell if it would work or not
  -U, --upgrade=+     upgrade package(s)
  --reinstall=+       reinstall package(s)

Common options for all rpm modes and executables:
  -D, --define='MACRO EXPR'        define MACRO with value EXPR
  --undefine=MACRO                 undefine MACRO
  -E, --eval='EXPR'                print macro expansion of EXPR
  --macros=<FILE:...>              read <FILE:...> instead of default file(s)
  --noplugins                      don't enable any plugins
  --nodigest                       don't verify package digest(s)
  --nosignature                    don't verify package signature(s)
  --rcfile=<FILE:...>              read <FILE:...> instead of default file(s)
  -r, --root=ROOT                  use ROOT as top level directory (default: "/")
  --dbpath=DIRECTORY               use database in DIRECTORY
  --querytags                      display known query tags
  --showrc                         display final rpmrc and macro configuration
  --quiet                          provide less detailed output
  -v, --verbose                    provide more detailed output
  --version                        print the version of rpm being used

Options implemented via popt alias/exec:
  --scripts                        list install/erase scriptlets from package(s)
  --setperms                       set permissions of files in a package
  --setugids                       set user/group ownership of files in a package
  --conflicts                      list capabilities this package conflicts with
  --obsoletes                      list other packages removed by installing this package
  --provides                       list capabilities that this package provides
  --requires                       list capabilities required by package(s)
  --info                           list descriptive information from package(s)
  --changelog                      list change logs for this package
  --xml                            list metadata in xml
  --triggers                       list trigger scriptlets from package(s)
  --last                           list package(s) by install time, most recent first
  --dupes                          list duplicated packages
  --filesbypkg                     list all files from each package
  --fileclass                      list file names with classes
  --filecolor                      list file names with colors
  --fscontext                      list file names with security context from file system
  --fileprovide                    list file names with provides
  --filerequire                    list file names with requires
  --filecaps                       list file names with POSIX1.e capabilities

Help options:
  -?, --help                       Show this help message
  --usage                          Display brief usage message

NOTE: rpm also is available via alias repoquery. This alias is created when you install the yum-utils package and it displays different behaviour that rpm despite the fact that it is aan alias to the same binary. It might be more convenient to use in some cases.

[0]ronserver@ROOT:~ # repoquery
Usage: repoquery [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -l, --list            list files in this package/group
  -i, --info            list descriptive info from this package/group
  -f, --file            query which package provides this file
  --qf=QUERYFORMAT, --queryformat=QUERYFORMAT
                        specify a custom output format for queries
  --groupmember         list which group(s) this package belongs to
  -q, --query           no-op for rpmquery compatibility
  -a, --all             query all packages/groups
  -R, --requires        list package dependencies
  --provides            list capabilities this package provides
  --obsoletes           list other packages obsoleted by this package
  --conflicts           list capabilities this package conflicts with
  --changelog           show changelog for this package
  --location            show download URL for this package
  --nevra               show name-epoch:version-release.architecture info of
                        package
  --envra               show epoch:name-version-release.architecture info of
                        package
  --nvr                 show name, version, release info of package
  -s, --source          show package source RPM name
  --srpm                operate on corresponding source RPM
  --resolve             resolve capabilities to originating package(s)
  --alldeps             check non-explicit dependencies (files and Provides:)
                        as well, defaults to on
  --exactdeps           check dependencies exactly as given, opposite of
                        --alldeps
  --recursive           recursively query for packages (for whatrequires)
  --whatprovides        query what package(s) provide a capability
  --whatrequires        query what package(s) require a capability
  --whatobsoletes       query what package(s) obsolete a capability
  --whatconflicts       query what package(s) conflicts with a capability
  -g, --group           query groups instead of packages
  --grouppkgs=GROUPPKGS
                        filter which packages (all,optional etc) are shown
                        from groups
  --archlist=ARCHLIST   only query packages of certain architecture(s)
  --releasever=RELEASEVER
                        set value of $releasever in yum config and repo files
  --pkgnarrow=PKGNARROW
                        limit query to installed / available / recent /
                        updates / extras / all (available + installed) /
                        repository (default) packages
  --installed           limit query to installed pkgs only
  --show-duplicates     show all versions of packages
  --repoid=REPOID       specify repoids to query, can be specified multiple
                        times (default is all enabled)
  --enablerepo=ENABLEREPOS
                        specify additional repoids to query, can be specified
                        multiple times
  --disablerepo=DISABLEREPOS
                        specify repoids to disable, can be specified multiple
                        times
  --repofrompath=REPOFROMPATH
                        specify repoid & paths of additional repositories -
                        unique repoid and complete path required, can be
                        specified multiple times. Example.
                        --repofrompath=myrepo,/path/to/repo
  --plugins             enable yum plugin support
  --quiet               quiet output, only error output to stderr (default
                        enabled)
  --verbose             verbose output (opposite of quiet)
  -C, --cache           run from cache only
  --tempcache           use private cache (default when used as non-root)
  --querytags           list available tags in queryformat queries
  -c CONFFILE, --config=CONFFILE
                        config file location
  --level=TREE_LEVEL    levels to display (can be any number or 'all', default
                        to 'all')
  --output=OUTPUT       output format to use (can be text|ascii-tree|dot-tree,
                        default to 'text')
  --search              Use yum's search to return pkgs
  --search-fields=SEARCHFIELDS
                        search fields to search using --search
  --installroot=INSTALLROOT
                        set install root
  --setopt=SETOPTS      set arbitrary config and repo options

The repoquery command is pretty similar to the rpm -q command and uses many similar options. There is just one significant option missing: the --script option. A simple solution is to make sure that you are using trusted repositories only, to prevent installing software that contains dangerous script code.

If you need to thoroughly analyze what an RPM package is doing when it is installed, you can download it to your machine, which allows you to use the rpm -qp --scripts command on the package. To download a package from the repository to the local directory, you can use the yumdownloader command, which comes from the yum-utils package or user option d in yum (new for RHEL7)

To see information about the amanda package in your current directory, add the -i option to the rpm -qp
command line as follows:
# rpm -qpi amanda-2.6.1p2-7.el6.x86_64.rpm
Name : amanda Relocations: (not relocatable)
Version : 2.6.1p2 Vendor: Red Hat, Inc.
Release : 7.el6 Build Date: Wed 23 Jun 2010 07:39:33 AM EDT
Install Date: (not installed) Build Host: x86-007.build.bos.redhat.com
Group : Applications/System Source RPM: amanda-2.6.1p2-7.el6.src.rpm
Size : 1816241 License: BSD and LGPLv2 and GPLv3+ and GPLv2
Signature: RSA/8, Mon 16 Aug 2010 11:21:56 AM EDT, Key ID 199e2f91fd431d51
Packager : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
URL : http://www.amanda.org
Summary : A network-capable tape backup solution
Description :
AMANDA, the Advanced Maryland Automatic Network Disk Archiver, is a backup system
that allows the administrator of a LAN to set up a single master backup server to
back up multiple hosts to one or more tape drives or disk files. AMANDA uses
native dump and/or GNU tar facilities and can back up a large number of
workstations running multiple versions of Unix. Newer versions of AMANDA
(including this version) can use SAMBA to back up Microsoft(TM) Windows95/NT
hosts.
The amanda package contains the core AMANDA programs and will need to be installed
on both AMANDA clients and AMANDA servers. Note that you will have to install the
amanda-client and/or amanda-server packages as well.

There are five basic modes for RPM command

  1. Install : It is used to install any RPM package.
  2. Remove : It is used to erase, remove or un-install any RPM package.
  3. Upgrade : It is used to update the existing RPM package.
  4. Verify : It is used to verify an RPM packages.
  5. Query : It is used query any RPM package.

Where to find RPM packages

Below is the list of rpm sites, where you can find and download all RPM packages.

  1. http://rpmfind.net
  2. http://www.redhat.com
  3. http://freshrpms.net/
  4. http://rpm.pbone.net/

Read Also :

  1. 20 YUM Command Examples in Linux
  2. 10 Wget Command Examples in Linux
  3. 30 Most Useful Linux Commands for System Administrators

Please remember you must be root user when installing packages in Linux, with the root privileges you can manage rpm commands with their appropriate options.

1. How to Check an RPM Signature Package

Always check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is OK. Use the following command with –checksig (check signature) option to check the signature of a package called pidgin.

[root@ronserver]# rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm

pidgin-2.7.9-5.el6.2.i686.rpm: rsa sha1 (md5) pgp md5 OK

2. How to Install an RPM Package

For installing an rpm software package, use the following command with -i option. For example, to install an rpm package called pidgin-2.7.9-5.el6.2.i686.rpm.

[root@ronserver]# rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm

Preparing...                ########################################### [100%]
   1:pidgin                 ########################################### [100%]
RPM command and options
  1. -i : install a package
  2. -v : verbose for a nicer display
  3. -h: print hash marks as the package archive is unpacked.

3. How to check dependencies of RPM Package before Installing

Let’s say you would like to do a dependency check before installing or upgrading a package. For example, use the following command to check the dependencies of BitTorrent-5.2.2-1-Python2.4.noarch.rpm package. It will display the list of dependencies of package.

[root@ronserver]# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm

/usr/bin/python2.4
python >= 2.3
python(abi) = 2.4
python-crypto >= 2.0
python-psyco
python-twisted >= 2.0
python-zopeinterface
rpmlib(CompressedFileNames) = 2.6
RPM command and options
  1. -q : Query a package
  2. -p : List capabilities this package provides.
  3. -R: List capabilities on which this package depends..

4. How to Install a RPM Package Without Dependencies

If you know that all needed packages are already installed and RPM is just being stupid, you can ignore those dependencies by using the option –nodeps (no dependencies check) before installing the package.

[root@ronserver]# rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm

Preparing...                ########################################### [100%]
   1:BitTorrent             ########################################### [100%]

The above command forcefully install rpm package by ignoring dependencies errors, but if those dependency files are missing, then the program will not work at all, until you install them.

5. How to check an Installed RPM Package

Using -q option with package name, will show whether an rpm installed or not.

[root@ronserver]# rpm -q BitTorrent

BitTorrent-5.2.2-1.noarch

6. How to List all files of an installed RPM package

To view all the files of an installed rpm packages, use the -ql (query list) with rpm command.

[root@ronserver]# rpm -ql BitTorrent

/usr/bin/bittorrent
/usr/bin/bittorrent-console
/usr/bin/bittorrent-curses
/usr/bin/bittorrent-tracker
/usr/bin/changetracker-console
/usr/bin/launchmany-console
/usr/bin/launchmany-curses
/usr/bin/maketorrent
/usr/bin/maketorrent-console
/usr/bin/torrentinfo-console

7. How to List Recently Installed RPM Packages

Use the following rpm command with -qa (query all) option, will list all the recently installed rpm packages.

[root@ronserver]# rpm -qa --last

BitTorrent-5.2.2-1.noarch                     Tue 04 Dec 2012 05:14:06 PM BDT
pidgin-2.7.9-5.el6.2.i686                     Tue 04 Dec 2012 05:13:51 PM BDT
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686       Tue 04 Dec 2012 04:43:06 PM BDT
cyrus-sasl-2.1.23-13.el6_3.1.i686             Tue 04 Dec 2012 04:43:05 PM BDT
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686         Tue 04 Dec 2012 04:43:04 PM BDT
cyrus-sasl-plain-2.1.23-13.el6_3.1.i686       Tue 04 Dec 2012 04:43:03 PM BDT

8. How to List All Installed RPM Packages

Type the following command to print the all the names of installed packages on your Linux system.

[root@ronserver]# rpm -qa

initscripts-9.03.31-2.el6.centos.i686
polkit-desktop-policy-0.96-2.el6_0.1.noarch
thunderbird-17.0-1.el6.remi.i686

9. How to Upgrade a RPM Package

If we want to upgrade any RPM package “–U” (upgrade) option will be used. One of the major advantages of using this option is that it will not only upgrade the latest version of any package, but it will also maintain the backup of the older package so that in case if the newer upgraded package does not run the previously installed package can be used again.

[root@ronserver]# rpm -Uvh nx-3.5.0-2.el6.centos.i686.rpm
Preparing...                ########################################### [100%]
   1:nx                     ########################################### [100%]

10. How to Remove a RPM Package

To un-install an RPM package, for example we use the package name nx, not the original package name nx-3.5.0-2.el6.centos.i686.rpm. The -e (erase) option is used to remove package.

[root@ronserver]# rpm -evv nx

11. How to Remove an RPM Package Without Dependencies

The –nodeps (Do not check dependencies) option forcefully remove the rpm package from the system. But keep in mind removing particular package may break other working applications.

[root@ronserver]# rpm -ev --nodeps vsftpd

12. How to Query a file that belongs which RPM Package

Let’s say, you have list of files and you would like to find out which package belongs to these files. For example, the following command with -qf (query file) option will show you a file /usr/bin/htpasswd is own by package httpd-tools-2.2.15-15.el6.centos.1.i686.

[root@ronserver]# rpm -qf /usr/bin/htpasswd

httpd-tools-2.2.15-15.el6.centos.1.i686

13. How to Query a Information of Installed RPM Package

Let’s say you have installed an rpm package and want to know the information about the package. The following -qi (query info) option will print the available information of the installed package.

[root@ronserver]# rpm -qi vsftpd

Name        : vsftpd				   Relocations: (not relocatable)
Version     : 2.2.2				   Vendor: CentOS
Release     : 11.el6				   Build Date: Fri 22 Jun 2012 01:54:24 PM BDT
Install Date: Mon 17 Sep 2012 07:55:28 PM BDT      Build Host: c6b8.bsys.dev.centos.org
Group       : System Environment/Daemons           Source RPM: vsftpd-2.2.2-11.el6.src.rpm
Size        : 351932                               License: GPLv2 with exceptions
Signature   : RSA/SHA1, Mon 25 Jun 2012 04:07:34 AM BDT, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://vsftpd.beasts.org/
Summary     : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.

14. Get the Information of RPM Package Before Installing

You have download a package from the internet and want to know the information of a package before installing. For example, the following option -qip (query info package) will print the information of a package sqlbuddy.

[root@ronserver]# rpm -qip sqlbuddy-1.3.3-1.noarch.rpm

Name        : sqlbuddy                     Relocations: (not relocatable)
Version     : 1.3.3                        Vendor: (none)
Release     : 1                            Build Date: Wed 02 Nov 2011 11:01:21 PM BDT
Install Date: (not installed)              Build Host: rpm.bar.baz
Group       : Applications/Internet        Source RPM: sqlbuddy-1.3.3-1.src.rpm
Size        : 1155804                      License: MIT
Signature   : (none)
Packager    : Erik M Jacobs
URL         : http://www.sqlbuddy.com/
Summary     : SQL Buddy â Web based MySQL administration
Description :
SQLBuddy is a PHP script that allows for web-based MySQL administration.

15. How to Query documentation of Installed RPM Package

To get the list of available documentation of an installed package, use the following command with option -qdf (query document file) will display the manual pages related to vmstat package.

[root@ronserver]# rpm -qdf /usr/bin/vmstat

/usr/share/doc/procps-3.2.8/BUGS
/usr/share/doc/procps-3.2.8/COPYING
/usr/share/doc/procps-3.2.8/COPYING.LIB
/usr/share/doc/procps-3.2.8/FAQ
/usr/share/doc/procps-3.2.8/NEWS
/usr/share/doc/procps-3.2.8/TODO

16. How to Verify a RPM Package

Verifying a package compares information of installed files of the package against the rpm database. The -Vp (verify package) is used to verify a package.

[root@ronserver downloads]# rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm

S.5....T.  c /etc/httpd/conf.d/sqlbuddy.conf

17. How to Verify all RPM Packages

Type the following command to verify all the installed rpm packages.

[root@ronserver]# rpm -Va

S.5....T.  c /etc/rc.d/rc.local
.......T.  c /etc/dnsmasq.conf
.......T.    /etc/ld.so.conf.d/kernel-2.6.32-279.5.2.el6.i686.conf
S.5....T.  c /etc/yum.conf
S.5....T.  c /etc/yum.repos.d/epel.repo

18. How to Import an RPM GPG key

To verify RHEL/CentOS/Fedora packages, you must import the GPG key. To do so, execute the following command. It will import CentOS 6 GPG key.

[root@ronserver]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

19. How to List all Imported RPM GPG keys

To print all the imported GPG keys in your system, use the following command.

[root@ronserver]# rpm -qa gpg-pubkey*

gpg-pubkey-0608b895-4bd22942
gpg-pubkey-7fac5991-4615767f
gpg-pubkey-0f2672c8-4cd950ee
gpg-pubkey-c105b9de-4e0fd3a3
gpg-pubkey-00f97f56-467e318a
gpg-pubkey-6b8d79e6-3f49313d
gpg-pubkey-849c449f-4cb9df30

20. How To rebuild Corrupted RPM Database

Sometimes rpm database gets corrupted and stops all the functionality of rpm and other applications on the system. So, at the time we need to rebuild the rpm database and restore it with the help of following command.

[root@ronserver]# cd /var/lib
[root@ronserver]# rm __db*
[root@ronserver]# rpm --rebuilddb
[root@ronserver]# rpmdb_verify Packages

Ron Jagannathan has written 54 articles

Ronan is a Caffeine dependent life-form from Planet Earth who wants to be a Jedi Knight of cloud computing. A man of mystery and power, whose power is exceeded only by his mystery. Quantum Physicist, TransHumanist, Systems Architect, Unix Administrator, Artificial Intelligence, Machine Learning and DIY Gadget enthusiast. Believes that the Universe has a high probability of being a simulation.
But he's real and hopefully some of his readers are too.
email: Ron.Jagannathan@gmail.com ph: 202 355 5205
https://www.linkedin.com/in/ronjagan/
My Famous Quotes:
“In a Unix Universe, God is known by a four letter word called root. To err is human...to really foul requires you to be root.. err.. god.” ― Ron Jagannathan

Github: github.com/ronjag
Linkedin: linkedin.com/in/ronjagan/

“Quotes found on the Internet are not always accurate.” ― Abraham Lincoln

One thought on “All about RPM ( redhat Package Manager) HowTos

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>