28 Most Commonly Used RPM Commands in Linux

RPM Commands

The Red Hat Package Manager (RPM) is a powerful package management tool used in RHEL-based Linux distributions such as CentOS, Fedora, and Rocky Linux. It allows users to install, query, verify, and manage .rpm packages efficiently. Understanding RPM commands is essential for system administrators and developers working with these distributions.

Before working with RPM, you may need to verify the details of your operating system. Use the following commands to check your OS version and other relevant details:

cat /etc/os-release
cat /etc/system-release
cat /etc/redhat-release
uname -a

The RPM database, which stores information about installed packages, is located in /var/lib/rpm. You can list its contents with:

ls /var/lib/rpm

Example Output:

/var/lib/rpmdb.sqlite
/var/lib/rpmdb.sqlite-shm

RPM commands follow a specific syntax:

rpm [options] [package_name/.rpm file]

Now, let’s explore various RPM commands in detail.

  1. Check the installed version of RPM
  2. Get help for RPM commands
  3. Check if a package is installed
  4. List all installed packages
  5. Count the number of installed packages
  6. Sort installed packages by installation date
  7. Search for a package by name
  8. Show detailed package information
  9. List all files installed by a package
  10. List only configuration files of a package
  11. List documentation files for a package
  12. Show dependencies required by a package
  13. Identify which package installed a specific file
  14. Get details of an .rpm file before installing
  15. List configuration files in an .rpm package
  16. List all files included in an .rpm package
  17. List documentation files in an .rpm package
  18. Check dependencies required by an .rpm package
  19. Check the license of an .rpm package
  20. Check if package files have changed
  21. Verify a package in verbose mode
  22. Install an .rpm package
  23. Install an .rpm package without dependency checks
  24. Install an .rpm package with verbose output and progress indicator
  25. Upgrade an existing package or install it if not present
  26. Remove an installed package
  27. Remove a package with verbose output
  28. Remove a package without checking dependencies

1. Check the installed version of RPM:

rpm --version

This command displays the version of the RPM tool installed on your system.

2. Get help for RPM commands:

rpm --help

Displays a help message listing all available RPM options and command usages.

3. Check if a package is installed:

rpm -q package_name

Queries the RPM database to check if a specific package is installed.

4. List all installed packages:

rpm -qa

Lists all packages currently installed on the system.

5. Count the number of installed packages:

rpm -qa | wc -l

Combines rpm -qa with wc -l to count how many packages are installed.

6. Sort installed packages by installation date:

rpm -qa --last

Displays installed packages with the most recently installed packages listed first.

7. Search for a package by name:

rpm -qa | grep package_name

Searches the installed packages for a specific name using grep.

8. Show detailed package information:

rpm -qi package_name

Displays information about the package, like version, release, install date, and description.

9. List all files installed by a package:

rpm -ql package_name

Shows all files that were installed with a specific package.

10. List only configuration files of a package:

rpm -qc package_name

Lists the configuration files provided by the package.

11. List documentation files for a package:

rpm -qd package_name

Lists all documentation files installed by the package.

12. Show dependencies required by a package:

rpm -qR package_name

Lists all dependencies that the package requires to function.

13. Identify which package installed a specific file:

rpm -qf /path/to/file

Finds out which package the specified file belongs to.

14. Get details of an .rpm file before installing:

rpm -qip package_file.rpm

Shows detailed information about an RPM file without installing it.

15. List configuration files in an .rpm package:

rpm -qcp package_file.rpm

Lists the configuration files included in the RPM file.

16. List all files included in an .rpm package:

rpm -qlp package_file.rpm

Shows all files that will be installed from an RPM file.

17. List documentation files in an .rpm package:

rpm -qdp package_file.rpm

Lists documentation files from an RPM file before installation.

18. Check dependencies required by an .rpm package:

rpm -qRp package_file.rpm

Lists the dependencies required by the RPM file before installation.

19. Check the license of an .rpm package:

rpm -qip package_file.rpm | grep License

Filters package details to show the license type of the package.

20. Check if package files have changed:

rpm -V package_name

Verifies the integrity of package files (e.g., if they’ve been modified, deleted, or corrupted).

21. Verify a package in verbose mode:

rpm -Vv package_name

Like above, but shows more details during the verification process.

22. Install an .rpm package:

rpm -i package_file.rpm

Installs a new RPM package.

23. Install an .rpm package without dependency checks:

rpm -i --nodeps package_file.rpm

Installs the package but skips checking for dependencies (use cautiously).

24. Install an .rpm package with verbose output and progress indicator:

rpm -ivh package_file.rpm

Installs the package with detailed output and shows progress with hash marks.

25. Upgrade an existing package or install it if not present:

rpm -U package_file.rpm

Upgrades the package if it’s already installed, or installs it otherwise.

26. Remove an installed package:

rpm -e package_name

Uninstalls a package from the system.

27. Remove a package with verbose output:

rpm -evh package_name

Like above, but with verbose output and progress shown.

28. Remove a package without checking dependencies:

rpm -e --nodeps package_name

Forces package removal without checking if other packages depend on it.

Conclusion

Understanding and using RPM commands effectively is essential for managing software on RHEL-based systems. From querying installed packages to verifying integrity and managing .rpm files, mastering these commands ensures efficient package management and system maintenance.

Whether you’re a system administrator or a Linux enthusiast, these commands will help you streamline software management tasks with ease.

Related Posts

Leave a Reply