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.
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to install rpm package](https://www.golinuxcloud.com/wp-content/uploads/rpm-install-package.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] check an installed rpm package with rpm commnd](https://www.golinuxcloud.com/wp-content/uploads/q.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to update package](https://www.golinuxcloud.com/wp-content/uploads/rpm-update.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to remove installed package](https://www.golinuxcloud.com/wp-content/uploads/rpm-remove-package.png)
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.
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to remove rpm package](https://www.golinuxcloud.com/wp-content/uploads/rpm-erase-failed-e1632218175660.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to check dependencies](https://www.golinuxcloud.com/wp-content/uploads/rpm-check-dependencies.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to print information of rpm package](https://www.golinuxcloud.com/wp-content/uploads/print-information-of-rpm-package.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to get information of installed package](https://www.golinuxcloud.com/wp-content/uploads/get-info-installed-package.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to install pckage without dependencies](https://www.golinuxcloud.com/wp-content/uploads/rpm-install-nodeps.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to list all files of installed package](https://www.golinuxcloud.com/wp-content/uploads/list-files-of-installed-package.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to remove package without dependencies](https://www.golinuxcloud.com/wp-content/uploads/rpm-remove-nodeps.png)
Now, let's check if the package is removed.
![15+ rpm command examples in Linux [Cheat Sheet] rpm nodeps command](https://www.golinuxcloud.com/wp-content/uploads/dependencies-not-removed-e1632237202560.png)
The package is removed, but the dependencies are still present in the system.
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to list all installed packages](https://www.golinuxcloud.com/wp-content/uploads/rpm-list-installed-package.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to list recently installed packages](https://www.golinuxcloud.com/wp-content/uploads/list-recently-installed-packages.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to verify rpm paackage](https://www.golinuxcloud.com/wp-content/uploads/verify-rpm-package-e1632120472827.png)
14. rpm command to verify all RPM packages
You can use this command to verify all RPM packages.
$ sudo rpm -Va
Sample Output:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to verify all packages](https://www.golinuxcloud.com/wp-content/uploads/rpm-verify-all-packages.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to query file](https://www.golinuxcloud.com/wp-content/uploads/rpm-query-file.png)
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:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to check signatures](https://www.golinuxcloud.com/wp-content/uploads/rpm-checksig-e1632144681886.png)
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:
You can list all imported GPG keys with the following command.
$ sudo rpm -qa gpg-pubkey*
Sample Output:
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to list all imported gpg keys](https://www.golinuxcloud.com/wp-content/uploads/list-all-imported-gpg.png)
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
![15+ rpm command examples in Linux [Cheat Sheet] rpm command to import gpg key](https://www.golinuxcloud.com/wp-content/uploads/import-gpg-key.png)

