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
--install option to install an RPM package on your system. The RPM package must be available in your workstation.
$ sudo rpm -i rpm_filename
$ sudo rpm --install rpm_filename
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.
- -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
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
--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
$ sudo rpm --upgrade rpm_filename
4. Remove an RPM package with rpm command
You can remove an installed package from your system with
$ sudo rpm -e package_name
$ sudo rpm --erase package_name
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
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
- -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
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
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
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
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
Now, let's check if the package is removed.
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
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
13. Verify an RPM package with rpm command
--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
$ sudo rpm --verify -p rpm_filename
14. rpm command to verify all RPM packages
You can use this command to verify all RPM packages.
$ sudo rpm -Va
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]
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
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
You can list all imported GPG keys with the following command.
$ sudo rpm -qa gpg-pubkey*
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.