rpm Command in Linux

Learn via video courses
Topics Covered

Overview

In the Linux ecosystem, the rpm command serves as a robust utility for package management. Standing for Red Hat Package Manager, the rpm command in Linux offers the ability to install, uninstall, upgrade, query, and verify packages. It's a critical tool for system administrators, offering an efficient method for managing software on Linux distributions that use .rpm packages.

Syntax of rpm Command in Linux

The basic syntax of the rpm command in Linux is as follows:

Where:

  • options: These are the flags or switches that you can use with the rpm command. They tell the command what function to perform, such as installing, upgrading, or querying a package.
  • package_file | package_name: This is the specific .rpm package file or the installed package name you're dealing with. It could be a package you're looking to install, upgrade, verify, or remove.

Options in rpm Command in Linux

  1. -i | --install: This option is used to install a new package.

    For example -

    This command will install the 'sample_package.rpm' package.

  2. -q | --query: This option is used to query an installed package or a .rpm package file.

    For example -

    Output:

    This command queries the installed 'sample_package' and returns its version if it exists.

  3. -e | --erase: This option is used to remove an installed package.

    For example -

    This command will remove the installed 'sample_package'.

Example Usages

  • Installing a package:

    Explanation: This usage of the rpm command in Linux installs 'sample_package.rpm'.

  • Querying a package:

    Output:

    Explanation: This usage queries the installed 'sample_package' and returns its version.

Tips

  • You can use the -v option along with -i, -e, or -U to get more detailed output.

  • To install or uninstall packages, you need to have root permissions or use sudo.

Advanced Use Cases of rpm Command in Linux

  • Upgrade a package:

    Explanation: This command will upgrade the 'sample_package' to the version provided in the .rpm file, or install it if it doesn't exist.

  • Query all installed packages:

    Output:

    Explanation: This command lists all installed packages on the system.

  • Verify an installed package:

    Explanation: This command verifies the integrity of the installed 'sample_package'. It compares the size, digest, permissions, type, owner, group, modification time, and capabilities of each file against the values from the database.

Conclusion

  • The rpm command in Linux provides a powerful tool for managing software packages.

  • The command includes options to install, uninstall, upgrade, query, and verify packages.

  • Being familiar with the rpm command is essential for system administrators managing Linux distributions that use .rpm packages.