Interview Questions : Linux Package Manager (RPM)

This post will cover the most frequently reported how-to questions of Enterprise Linux Common Package Manager (RPM). Although not often used, rpm is a must know when you are facing a Linux interview.

What is RPM?

RPM stands for Red Hat Package Manager which provides for installing, upgrading and removing packages on Linux distributions. It is a free software tool. Originally developed by Red Hat for Red Hat Linux, RPM is now used by many Linux distributions. It has also been ported to some other operating systems, such as Suse Linux and IBM’s AIX as of version 5.

What main types of RPM?

There are two main types of RPM packages: binary (or applications) and source.A binary RPM has been compiled for a particular architecture.Source code RPMs which provide the source code for other packages.The package name ending with suffix src.rpm such as:

Binary Package: xpdf-3.00-11.12.i386.rpm
Source code package: xpdf-3.00-11.12.src.rpm

How to check the package is installed?

Use the “rpm –q” command to quickly verify a package has been installed. To verify, you need to use the name of the installed package, not the name of the RPM file. You can also use a partial package name. Alternatively,you can use command “rpm -qa |grep key-word” which will show you much more packages.

How to get more detail information while installing a rpm package?

The syntax for the command is

# rpm -Uhv package

This will print out # signs with -h option and the -v option print out verbose information as the command runs. You can install a package more than once. The rpm command won’t complain. The upgrade operation, though, will remove all other versions of a package. This is one more reason to use the –U upgrade option.

How to upgrade the kernel?

From the perspective of security, a new kernel should be installed with the “-i” flag rather than upgraded with “-U” flag. So that the previous version is still installed and can be used in the event that the new kernel does not work. E.g:

# rpm -ivh kernel-2.6.9-78.0.0.0.1.EL4.I686rpm

How to show the percentage completed as the rpm command executes?

The basic syntax is:

# rpm -U --percent package

The –percent option prints out decimal numbers that show the percentage completed as the rpm command executes. This option is most useful if you wrap the rpm command within some other command, such as a graphical user interface created from a Perl, Python, or Tcl/Tk script.

What is the detail process as install a RPM package?

You can use the rpm –U command or the rpm –i command to install a package. When the rpm command installs a package, it goes through a number of steps:

  • Checking the package and the files it wants to install
  • Performing preinstallation tasks
  • Uncompressing the files and placing them in the proper locations
  • Performing post-processing tasks
  • Updating the RPM Database

How to test a rpm command?

The –test command-line option tells the rpm command to test the installation or upgrade process but not to install the file. Such as:

# rpm -U --test eruby-devel-0.9.8-2.i386.rpm

How to install or upgrade a number of packages at the same time?

Just list each file name on the rpm command line. The basic syntax follows:

# rpm -U package1.rpm package2.rpm .. package100.rpm

How to install rpm package in different directories?

The –prefix and –relocate options should make the rpm command relocate a package to a new location. Not all packages allow relocations, though. The basic format of the command with the –prefix option is:

# rpm -U --prefix /new/directory package.rpm

With the –relocate option, the command format is:

# rpm -i --relocate /old/directory=/new/directory package.rpm

You can also use the –root option to specify a different directory for the rpm command to assume is the system’s root, or /, directory. This causes the rpm command to install files under the new root, instead of in system locations under /. This option is most useful for testing the installation of a complete system under a test directory. The command should use the following format:

# rpm -U --root /tmp --dbpath /var/lib/rpm package.rpm

How to skip the script when install/remove a rpm package?

As part of the package installation, as well as removal, the RPM package may have scripts that the rpm command should run. These include pre- and post-installation scripts, as well as pre- and post-uninstallation scripts. These scripts can perform options such as automatically configuring the application based on the target environment. Table below summarizes these options.

Option Usage
–nopre Skip pre-installation scripts.
–nopost Skip post-installation scripts.
–nopreun Skip pre-uninstallation scripts.
–nopostun Skip post-uninstallation scripts.
–noscripts Skip all the scripts; same as –nopre, –nopost, –nopreun, and –nopostun.

During installation, you can tell the rpm command not to execute all the triggers or not to execute certain triggers. The –notriggers option tells the rpm command to skip all triggers.

Option Usage
–notriggerin Skip installation triggers.
–notriggerun Skip uninstallation triggers.
–notriggerpostun Skip post-uninstallation triggers.
–notriggers Skip all the triggers; same as –notriggerin, — notriggerun, and — notriggerpostun.

What are ignore options with RPM?

The rpm command supports several ignore options that tell the command to ignore some aspect of a package it would normally complain about.

  • The –ignorearch option tells the rpm command to ignore the architecture of the package and install the package, even if the architecture of the package and the architecture of your system do not match. This is a very dangerous option.
  • The –ignoreos command-line option tells the rpm command to ignore the operating system. Again, this is likely not a good idea in most situations.
  • The –ignoresize option tells the rpm command to ignore or skip a check of your hard disk to ensure it has enough space to install the package. Warning: Don’t use the –ignoresize option if you have a nearly full hard disk, especially for a root, or /, partition.
  • The –nodigest option tells the rpm command to skip the test of the digest, the special value that helps verify the package correctness.
  • The –nosignature option tells the rpm command to skip the test of the digest, the encrypted key, that helps also verify the package correctness.

How to install/update rpm package via ftp?

The common syntax as following:

# rpm -i ftp://username:password@www.example.com/pub/rpms/sample_rpm.src.rpm

How to install/update rpm package via Http?

Similar to accessing a file via FTP, you need to pass the rpm command a URL identifying the file. For example:

# rpm –i http://ftp.redhat.com/pub/contrib/noarch/SRPMS/Squeak-sources-3-1.src.rpm

How to remove multiple packages at the same time?

The basic syntax follows:

# rpm -e package1.rpm package2.rpm .. package100.rpm

How to list the documentation files for a package?

The basic syntax is:

# rpm –qd package_name

How to list the files in a package?

The basic syntax is:

# rpm –ql package_name

How to list the scripts in a package?

The basic syntax is:

# rpm -q --scripts package_name

How to list what has changed for a package?

The basic format of the command is:

# rpm -q --changelog package_name

How to list the most recently installed packages?

The basic syntax is:

# rpm -qa --last

Command below will show more or fewer than ten lines.

# rpm -qa --last | head

How to create custom queries?

The basic syntax of the query format is %{tag_name}. For instance:

# rpm -q --qf "%{N}.%{V}--%{R}.%{ARCH}\n" kernel-smp

Above command will show the kernel-smp package full information as you custom. E.g:

# rpm -q --qf "%{N}.%{V}--%{R}.%{ARCH}\n" kernel-smp
kernel-smp.2.6.9--67.0.0.0.1.EL.i686

What is tags of package information supported by RPM?

Package-information query tags:

Tag Holds
NAME Package name
VERSION Version number
RELEASE Release number
SUMMARY One-line summary of the package contents
DESCRIPTION Descriptive text about the package
BUILDTIME Time package was built
BUILDHOST Host package was built on
SIZE Size of all the regular files in the payload
LICENSE License package was released under
GROUP Descriptive group or category name for the package
OS Operating system package was built for
ARCH Architecture, such as i386
SOURCERPM The associated source RPM
CHANGELOGTIME Array of changelog times
CHANGELOGNAME Array of changelog names
CHANGELOGTEXT Array of changelog text entries
PREIN Pre-install script
POSTIN Post-install script
PREUN Pre-uninstall script
POSTUN Post uninstall script
PLATFORM Platform

How to verify installed RPM packages?

The basic syntax is:

# rpm -V verify_options package_name

To verify your entire system, use the -a option.

How to determine what capabilities a package requires?

The basic syntax is:

# rpm -q query_options --requires packages

How to check what conflicts with a given package?

The basic syntax is:

# rpm –q query_options --conflicts packages
Related Post