15+ rpm command examples in Linux [Cheat Sheet]


CheatSheet

Reviewer: Deepak Prasad

Introduction to rpm command

RPM (Red Hat Package Manager) is an open-source package management tool in RHEL based systems such as RHEL, CentOS, and Fedora. You can install, update, remove, or verify RPM packages with this tool. RPM only works with .rpm files, so you need to have a .rpm file in your system. The .rpm file stores the installation packages of RPM-based Linux distribution.

 

Different examples to use rpm command

Since you will need to have .rpm files, you can download them from here. You can also use the dnf command to download the rpm package using this command.

$ sudo dnf install package_name --downloadonly --downloaddir=DIR_PATH

You can find our detailed article on dnf at 25+ DNF command practical examples in Linux.

In this article, we will learn how to use rpm commands to manage the RPM packages on the system.

 

1. rpm command to install an RPM package

You can use -i or --install option to install an RPM package on your system. The RPM package must be available in your workstation.

$ sudo rpm -i rpm_filename

OR

$ sudo rpm --install rpm_filename

Sample Output:

In the following example, we are installing single rpm. If this rpm has any dependency over other rpm then that must be manually handled by downloading that rpm and installing them both together or else the installation will fail with dependency error.

rpm command to install rpm package

Here,

  • -v: To display the verbose output
  • -h: To print the hash symbol progress bar

 

2. Check an installed RPM package with rpm command

You can use -q option to check whether an RPM package is installed in your system or not.

$ sudo rpm -q package_name

Sample Output:

check an installed rpm package with rpm commnd

As you can see, iotop is installed in our system. The package name that you provide may be incorrect, so you can also try the following command

$ sudo rpm -qa | grep package_name

This command can also help you check if the provided package is installed or not.

 

3. rpm command to upgrade an RPM package

-U or --upgrade option allows you to upgrade any RPM package to the latest version. This is the same as install, except all other version(s) of the package are removed after the new package is installed.

$ sudo rpm -U rpm_filename

OR

$ sudo rpm --upgrade rpm_filename

Sample Output:

rpm command to update package

 

4. Remove an RPM package with rpm command

You can remove an installed package from your system with -e or --erase option.

$ sudo rpm -e package_name

OR

$ sudo rpm --erase package_name

Sample Output:

rpm command to remove installed package

In some cases, this command fails to remove the package from the system due to unresolved dependencies. So, the best way to remove RPM packages and their dependencies is by using yum or dnf command.

rpm command to remove rpm package

 

5. Check dependencies of an RPM package using rpm command

This command allows you to check the dependencies of an RPM package on the system.

$ sudo rpm -qpR rpm_filename

Sample Output:

rpm command to check dependencies

Here,

  • -q: To query an RPM package
  • -p: To query an uninstalled package
  • -R: To list capabilities on which the package depends

 

6. rpm command to print the information of an RPM package

With the help of this command, you can get the information of an RPM package on your system.

$ sudo rpm -qip rpm_filename

Sample Output:

rpm command to print information of rpm package

 

7. rpm command to get information of an installed package

Sometimes, you may want to get the information of any installed packages on the system. In that case, you can use this command.

$ sudo rpm -qi package_name

Sample Output:

rpm command to get information of installed package

 

8. Install an RPM package without dependencies with rpm command

--nodeps option allows you to install an RPM package without dependencies. It ignores the dependencies errors and forcefully installs an RPM package. Some programs may not work until you install the required dependencies.

$ sudo rpm -ivh --nodeps rpm_filename

Sample Output:

rpm command to install pckage without dependencies

IMPORTANT NOTE:
This is strictly not recommended as this can potentially break your system for more complex rpms such as kernel, gcc etc.

 

9. rpm command to list all files of an installed RPM package

You can use this command to list all the files of an installed RPM package.

$ sudo rpm -ql package_name

Sample Output:

rpm command to list all files of installed package

 

10. Remove an RPM package without dependencies using rpm command

You can also use --nodeps option with the erase command to uninstall an RPM package without checking dependencies. It ignores all the dependencies errors and forcefully removes the package.

$ sudo rpm -ev --nodeps package_name

Sample Output:

rpm command to remove package without dependencies

Now, let's check if the package is removed.

rpm nodeps command

The package is removed, but the dependencies are still present in the system.

IMPORTANT NOTE:
This is strictly not recommended as this can potentially break your system for more complex rpms such as kernel, gcc.

 

11. List all installed RPM packages with rpm command

To view the list of all installed RPM packages in your system, you can use this command.

$ sudo rpm -qa

Sample Output:

rpm command to list all installed packages

 

12. List only recently installed RPM packages with rpm command

You can use this command to view the list of recently installed RPM packages on your system.

$ sudo rpm -qa --last

Sample Output:

rpm command to list recently installed packages

 

13. Verify an RPM package with rpm command

-V or --verify option allows you to verify an RPM package against the rpm database. It compares the installed package information with package metadata stored in the rpm database. It also compares the size, digest, permissions, type, owner, and group of each file.

$ sudo rpm -Vp rpm_filename

OR

$ sudo rpm --verify -p rpm_filename

Sample Output:

rpm command to verify rpm paackage

 

14. rpm command to verify all RPM packages

You can use this command to verify all RPM packages.

$ sudo rpm -Va

Sample Output:

rpm command to verify all packages

 

15. Query a file with rpm command

You can also query a file and find to which RPM package it belongs.

$ sudo rpm -qf [file_name or file_path]

Sample Output:

 

rpm command to query file

 

16. rpm command to check signatures in an RPM package

--checksig option checks all the digests and signatures contained in an RPM package file. It is a useful command to verify the integrity and origin of the package is ok.

$ sudo rpm --checksig rpm_filename

Sample Output:

rpm command to check signatures

 

17. Import an RPM GPG key with rpm command

You can import a GPG key with --import option. RPM GPG key files are located in the /etc/pki/rpm-gpg directory.

$ sudo rpm --import RPM-GPG-KEY_File

Sample Output:

rpm command to import gpg key

You can list all imported GPG keys with the following command.

$ sudo rpm -qa gpg-pubkey*

Sample Output:

rpm command to list all imported gpg keys

 

Conclusion

This article shows you the practical examples of rpm command on RPM-based Linux distribution. rpm is a powerful package manager tool to install, remove, update, query, and verify RPM packages. We hope that you can now manage the RPM packages using rpm command. If you have any questions, you can use the comment section below.

 

What's Next

Rpmbuild | Create rpm package | Build rpm from source code

 

Further Reading

man page for rpm command

 

Rohan Timalsina

Rohan Timalsina

He is proficient in a wide range of skills, including Page Builder Plugins such as Elementor, Beaver Builder, Visual Composer, and Divi Builder. His expertise extends to Front End Development with HTML5/CSS3, JavaScript, Bootstrap, and React.js. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment