How to use the RPM command (with examples)

How to use the RPM command (with examples)

The RPM Package Manager (RPM) is a powerful command-line tool used primarily in Red Hat-based Linux distributions such as Fedora, Red Hat Enterprise Linux, and CentOS. It allows users to manage software packages, providing capabilities such as installing, updating, removing, verifying, and querying packages. With a robust set of features, RPM is designed for software distribution and management, making it a critical tool for system administrators and anyone managing Linux systems.

Use case 1: Show version of httpd package

Code:

rpm --query httpd

Motivation for using the example:

In a Linux system, knowing the exact version of an installed package is crucial for debugging issues, ensuring compatibility, or simply verifying that the right version is in use. For example, if you’re troubleshooting a web server problem, knowing the current version of the httpd package can help determine if a bug present in a specific version is affecting your server.

Explanation of the command:

  • rpm: This is the command-line tool for managing RPM packages.
  • --query: This option tells RPM to query the package database to retrieve information.
  • httpd: This is the name of the package you are querying, in this case, the Apache HTTP Server package.

Example output:

httpd-2.4.46-1.el7.x86_64

This output indicates that the installed version of the httpd package is 2.4.46-1.el7 for the x86_64 architecture.

Use case 2: List versions of all matching packages

Code:

rpm --query --all 'mariadb*'

Motivation for using the example:

Systems may have multiple related packages installed, especially when dealing with robust and complex software like MariaDB. Listing all matching packages and their versions helps in understanding the setup, verifying consistency, and ensuring the entire suite of MariaDB components matches expected versions, crucial for maintenance and compatibility checks.

Explanation of the command:

  • rpm: The RPM package manager command.
  • --query: This option requests RPM to retrieve information.
  • --all: This parameter expands the query to all installed packages that match the specified criteria.
  • 'mariadb*': The wildcard 'mariadb*' indicates that RPM should find and list all packages with names starting with “mariadb”, covering all relevant components.

Example output:

mariadb-10.5.8-1.el7.x86_64
mariadb-libs-10.5.8-1.el7.x86_64
mariadb-server-10.5.8-1.el7.x86_64

This output shows all the installed MariaDB packages, each with a specific version.

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

Code:

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

Motivation for using the example:

There are scenarios where a system administrator needs to install a package that is older or has dependencies conflicting with currently installed versions. Using the --force option allows overriding existing installations, which is a powerful tool for addressing urgent compatibility issues, custom testing, or circumventing certain dependency conflicts that otherwise block installations.

Explanation of the command:

  • rpm: The command-line tool for managing RPM packages.
  • --upgrade: This command is used to upgrade or install a package.
  • path/to/package.rpm: The path specifies the exact location of the RPM file to be installed.
  • --force: This option tells RPM to force the installation of the package, disregarding constraints imposed by already installed versions or unmet dependencies.

Example output:

Preparing...                          ################################# [100%]
Updating / installing...
   1:package-version.arch             ################################# [100%]

This output indicates the package was forcibly installed.

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

Code:

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

Motivation for using the example:

System administrators often need to track configuration files to their originating packages for troubleshooting, compliance, or system audits. Knowing which package owns a file can help with configuring updates correctly or identifying which package caused a particular configuration file change.

Explanation of the command:

  • rpm: The tool for package management.
  • --query: The action to query the database.
  • --file: This command tells RPM to show which installed package owns the specified file.
  • /etc/postfix/main.cf: The specific file path to track.

Example output:

postfix-3.5.8-1.el7.x86_64

The output indicates the file /etc/postfix/main.cf belongs to the postfix package version 3.5.8-1.

Use case 5: List package-owned files

Code:

rpm --query --list kernel

Motivation for using the example:

Listing all files owned by a package allows administrators to better understand the package’s footprint. It is crucial for determining which files are installed, ensuring that configurations or binaries are in their expected locations, or preparing to clean up obsolete files during an uninstallation process.

Explanation of the command:

  • rpm: The command-line tool to manage RPM packages.
  • --query: This prompts RPM to query its database.
  • --list: This option specifies listing all files provided by the package.
  • kernel: The name of the specific package to examine.

Example output:

/boot/vmlinuz-3.10.0-1127.el7.x86_64
/usr/lib/modules/3.10.0-1127.el7.x86_64
...

This reveals all files installed by the kernel package.

Use case 6: Show scriptlets from an RPM file

Code:

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

Motivation for using the example:

Inspecting scriptlets in an RPM file is essential for understanding package behaviors during installation, upgrade, and removal processes. These scriptlets might contain necessary instructions for configuration or cleanup, impacting system performance or security if misused.

Explanation of the command:

  • rpm: The tool for handling RPM packages.
  • --query: Tells RPM to pull information on a package.
  • --package: Indicates RPM to operate on a package file, not the installed database.
  • --scripts: Requests details of all scriptlets from the RPM file being queried.
  • package.rpm: The RPM file to inspect.

Example output:

preinstall scriptlet (using /bin/sh):
# some pre-installation script
...
postremove scriptlet (using /bin/sh):
# some post-removal script

This output shows scripts meant to run at different package lifecycle stages.

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

Code:

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

Motivation for using the example:

Verifying package integrity is crucial in detecting accidental file changes, missing files, or corruption. Running this command against a suite like PHP ensures the whole application remains unaltered by unwanted modifications or system issues, maintaining application reliability and security.

Explanation of the command:

  • rpm: The RPM package manager command.
  • --verify: This option checks for discrepancies between installed files and the package database.
  • --all: Specifies that all matching installed packages should be verified.
  • 'php-*': The pattern to match all installed PHP-related packages.

Example output:

..5....T.  c /etc/php.ini

This output shows that the configuration file /etc/php.ini has changed (5) and its modification time (T) differs from the package metadata.

Use case 8: Display the changelog of a specific package

Code:

rpm --query --changelog package

Motivation for using the example:

Changelogs provide historical insights into what changes have been made in different versions of the software—vital for understanding new features, bug fixes, or potential regressions. Accessing the changelog helps in assessing whether an update is beneficial or inappropriate.

Explanation of the command:

  • rpm: The RPM package manager tool.
  • --query: Instructs RPM to gather information.
  • --changelog: Displays the changelog of the specified package.
  • package: The package for which to view the changelog.

Example output:

* Fri Mar 12 2023 John Doe <jdoe@example.com> - 2.6.2-1
- Fix issue with SSL configuration
- Add support for new protocol

* Mon Jan 18 2023 Jane Smith <jsmith@example.com> - 2.6.1-1
- Improve performance for large files
- Update documentation

This illustrates chronological updates recorded for the selected package.

Conclusion:

Each of the rpm command’s use cases addresses common tasks involved in Linux system administration—from package version checks to verification and changelog inspection. Understanding these use cases is crucial, as they equip administrators and users with the tools and knowledge to manage their systems effectively, ensuring consistent software performance, security, and up-to-date configurations.

Tags :

Related Posts

How to Use the Command 'Knife' (with Examples)

How to Use the Command 'Knife' (with Examples)

The knife command is an essential tool provided by Chef, a powerful configuration management system used for automating the deployment, configuration, and management of applications and infrastructure.

Read More
How to Use Tuxi for Efficient Google Scraping (with Examples)

How to Use Tuxi for Efficient Google Scraping (with Examples)

Tuxi is a powerful tool designed to seamlessly scrape Google search results and search engine results pages (SERPs), making it an invaluable resource for users seeking immediate, concise answers.

Read More
How to use the command 'mkfs.f2fs' (with examples)

How to use the command 'mkfs.f2fs' (with examples)

The mkfs.f2fs command is used to create a Flash-Friendly File System (F2FS) within a specified partition of a storage device.

Read More