How to use the command rpm (with examples)

How to use the command rpm (with examples)

Description:

The rpm command stands for RPM Package Manager. It is a powerful package management tool used on Linux systems. With rpm, you can query, install, upgrade, and manage software packages on your system. It provides a wide range of functionalities to handle RPM packages effectively.

Use case 1: Show version of httpd package

Code:

rpm --query httpd

Motivation: To retrieve the version of the installed httpd package, you can use the rpm command with the --query option followed by the package name. This is useful when you need to check the version of a specific package on your system.

Explanation:

  • --query specifies the action to query the package information.
  • httpd is the name of the package being queried.

Example output:

httpd-2.4.37-39.el8.x86_64

Use case 2: List versions of all matching packages

Code:

rpm --query --all 'mariadb*'

Motivation: To list all versions of packages whose names match a specific pattern (in this case starting with mariadb), you can use the rpm command with the --query option, --all flag, and the pattern.

Explanation:

  • --query specifies the action to query the package information.
  • --all flag lists all versions of packages matching the pattern 'mariadb*'.

Example output:

mariadb-1:10.5.12-1.el8.x86_64
mariadb-1:10.4.18-1.el8.x86_64
mariadb-1:10.3.29-1.el8.x86_64

Use case 3: Forcibly install a package regardless of currently installed versions

Code:

rpm --upgrade path/to/package.rpm --force

Motivation: This command is useful when you want to install a package regardless of any currently installed versions. It can help you override conflicts and force the installation of a specific package.

Explanation:

  • --upgrade specifies the action to upgrade an RPM package.
  • path/to/package.rpm is the path to the RPM package you want to install.
  • --force flag forces the installation of the package, ignoring any conflicts or dependencies.

Use case 4: Identify owner of a file and show version of the package

Code:

rpm --query --file /etc/postfix/main.cf

Motivation: When you have a file on your system and you want to know which package owns it, you can use the rpm command with the --query option and the --file flag followed by the file path. This can help in troubleshooting or understanding the origin of files on your system.

Explanation:

  • --query specifies the action to query the package information.
  • --file flag is used to specify the file path you want to identify the owner of.
  • /etc/postfix/main.cf is the file path being queried.

Example output:

postfix-3.3.1-13.module+el8.5.0+13267+8ada9f61.x86_64

Use case 5: List package-owned files

Code:

rpm --query --list kernel

Motivation: To list all files owned by a specific package (in this case, the kernel package), you can use the rpm command with the --query option, --list flag, and the package name. This provides a comprehensive list of files associated with the package.

Explanation:

  • --list flag lists all files owned by the specified package.
  • kernel is the name of the package being queried.

Example output:

/usr/src/kernels/4.18.0-302.el8.x86_64/Makefile
/usr/src/kernels/4.18.0-302.el8.x86_64/arch/alpha/kernel/asm-offsets.c
/usr/src/kernels/4.18.0-302.el8.x86_64/arch/alpha/kernel/asm-offsets.s
...

Use case 6: Show scriptlets from an RPM file

Code:

rpm --query --package --scripts package.rpm

Motivation: If you want to view the scriptlets contained within an RPM file, you can use the rpm command with the --query option, --package flag, and the path to the RPM file. This can be helpful to examine the pre- and post-installation scripts associated with the package.

Explanation:

  • --package specifies the action to query the package information.
  • --scripts flag displays the scriptlets included in the RPM package.
  • package.rpm is the path to the RPM file being queried.

Use case 7: Show changed, missing, and/or incorrectly installed files of matching packages

Code:

rpm --verify --all 'php-*'

Motivation: When you suspect that some files provided by matching packages may be corrupted, missing, or modified, you can use the rpm command with the --verify option, --all flag, and the pattern of package names. This command verifies the integrity of package files and reports any discrepancies.

Explanation:

  • --verify specifies the action to verify the integrity of package files.
  • --all flag applies the verification to all packages whose names match the provided pattern (php-* in this case).

Example output:

S.4...T. /usr/bin/php
S.5....T. /usr/sbin/php-fpm
missing   /usr/share/doc/php-common-7.4.23/CODING_STANDARDS-1.2.1.xml

Use case 8: Display the changelog of a specific package

Code:

rpm --query --changelog package

Motivation: To view the changelog of a specific package, you can use the rpm command with the --query option, --changelog flag, and the package name. This provides information about the history and changes made to the package over time.

Explanation:

  • --changelog flag displays the changelog of the specified package.
  • package is the name of the package being queried.

Conclusion:

The rpm command is a versatile package management tool that allows you to perform various operations on RPM packages. From querying package information to installing, upgrading, and verifying packages, rpm provides a comprehensive set of functionalities for managing software packages on Linux systems.

Tags :

Related Posts

How to use the command HTTPFlow (with examples)

How to use the command HTTPFlow (with examples)

HTTPFlow is a command-line utility designed to capture and dump HTTP streams.

Read More
How to use the command 'nmcli agent' (with examples)

How to use the command 'nmcli agent' (with examples)

The nmcli agent command is used to run nmcli as a NetworkManager secret agent or polkit agent.

Read More
Using the 'file' command (with examples)

Using the 'file' command (with examples)

The ‘file’ command is a powerful tool that allows users to determine the type of a file.

Read More