- 15+ rpm command examples in Linux [Cheat Sheet]
- Different examples to use rpm command
- 1. rpm command to install an RPM package
- 2. Check an installed RPM package with rpm command
- 3. rpm command to upgrade an RPM package
- 4. Remove an RPM package with rpm command
- 5. Check dependencies of an RPM package using rpm command
- 6. rpm command to print the information of an RPM package
- 7. rpm command to get information of an installed package
- 8. Install an RPM package without dependencies with rpm command
- 9. rpm command to list all files of an installed RPM package
- 10. Remove an RPM package without dependencies using rpm command
- 11. List all installed RPM packages with rpm command
- 12. List only recently installed RPM packages with rpm command
- 13. Verify an RPM package with rpm command
- 14. rpm command to verify all RPM packages
- 15. Query a file with rpm command
- 16. rpm command to check signatures in an RPM package
- 17. Import an RPM GPG key with rpm command
- Conclusion
- How to Install an RPM File On Linux OS (CentOS, RHEL, & Fedora)
- Step 1: Download RPM Installation File
- Step 2: Install RPM File on Linux
- Install RPM File Using RPM Command
- Install RPM File with Yum
- Install RPM on Fedora
- Remove RPM Package
- Download RPM Packages from the Repository
15+ rpm command examples in Linux [Cheat Sheet]
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 --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.
- -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.
Sample Output:
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 --upgrade rpm_filename
Sample Output:
4. Remove an RPM package with rpm command
You can remove an installed package from your system with -e or —erase option.
$ sudo rpm --erase package_name
Sample Output:
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.
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:
- -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:
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.
Sample Output:
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:
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.
Sample Output:
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:
Now, let’s check if the package is removed.
The package is removed, but the dependencies are still present in the system.
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.
Sample Output:
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.
Sample Output:
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 --verify -p rpm_filename
Sample Output:
14. rpm command to verify all RPM packages
You can use this command to verify all RPM packages.
Sample Output:
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:
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:
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.
Sample Output:
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.
How to Install an RPM File On Linux OS (CentOS, RHEL, & Fedora)
While working in Linux, you may have seen downloadable files with the .rpm extension. Rpm files are designed to be downloaded and installed independently, outside of a software repository.
This guide will show you how to install a .rpm file to your Linux CentOS or Fedora system.
Note: RPM Package Manager (RPM) is a free and open-source package management system for installing, uninstalling and managing software packages in Linux.
- A user account with sudo privileges
- Access to a terminal window / command line (Menu > applications > utilities > terminal, Ctrl-Alt-F2)
- RPM, DNF, & YUM Package Managers (all included by default)
Step 1: Download RPM Installation File
Typically, a web browser is used to locate and download a .rpm file. However, if a browser is not available you can still download a file if you know where it’s located.
You may need to install a software tool called wget .
To install wget in CentOS, enter the following in a terminal window:
To install wget in Fedora, enter the following:
Now, you can use the wget command to download the .rpm file you want. Enter the following:
wget http://some_website/sample_file.rpm
The system should reach out to the website and download the file to your current working directory.
Note: You can look up the address of a particular .rpm file in a web browser on another system. Also, this is a handy way to install more recent software versions or special non-standard software. Also, take care when installing software packages! Make sure you trust the source before you install. Usually, a developer will include a verification method to make sure you’re getting authentic software.
Step 2: Install RPM File on Linux
Install RPM File Using RPM Command
To install a .rpm package in CentOS Linux, enter the following:
sudo rpm -i sample_file.rpm
The -i switch tells the package manager you want to install the file.
More information on the RPM installer can be found in the RPM documentation.
Install RPM File with Yum
Alternately, you can use the yum package manager to install .rpm files.
sudo yum localinstall sample_file.rpm
The localinstall option instructions yum to look at your current working directory for the installation file.
Note: YUM stands for Yellowdog Updater Modified. Normally, yum looks to your enabled software repositories for new software packages to install. More recent verbiage suggests using install instead of localinstall, but it’s up to you.
Install RPM on Fedora
To install an .rpm package on Fedora Linux, enter the following:
sudo rpm -i sample_file.rpm
Just as in CentOS, the -i switch tells RPM to install the software.
Another method is to use the dnf utility to install the package:
sudo dnf localinstall sample_file.rpm
Unlike many Linux tools, DNF is not a set of initials. It is merely the next evolution of the yum package manager.
Remove RPM Package
The RPM installer can be used to remove (or uninstall) a software package.
Enter the following into a terminal window:
sudo rpm -e sample_file.rpm
The -e option instructs RPM to erase the software. Check RPM Dependencies
So far, this guide assumes the software either doesn’t have dependencies or already has them installed.
To check the .rpm file for dependencies using the following command:
sudo rpm -qpR sample_file.rpm
The system should list all the dependencies:
- -q – This option tells RPM to query the file
- -p – This option lets you specify the target package to query
- -R – This lists the requirements for the package
If there are any missing dependencies, you can install them from the standard repositories using yum or dnf. If your software requires other non-standard software, it will often be noted in the installation instructions.
Download RPM Packages from the Repository
One exciting feature of the yum package manager is that it allows you to download .rpm files directly from the repository. This might be helpful if you have limited bandwidth, or want to copy a single downloaded file between systems. It could also help if you have intermittent internet access, and you don’t want to spend time waiting for your installer to finish.
To download a .rpm file from the repositories, enter the following:
sudo yumdownloader packagename
If you wanted to download the files for Apache, for instance, you’d replace packagename with httpd. You can then install the file as above.
Note: In Linux, administrators find it helpful to have a single tool to manage software. That tool – called a package manager – can install software, keep track of software requirements, and track updates and patches. Package managers also work with repositories, which are secure and standardized libraries of commonly-used and well-supported applications. If you had to install wget in Step 1, that’s an example of installing from a repository.
In this tutorial, we covered three different options for installing RPM files on Linux.
As with most Linux software, your default package manager makes it simple to track installations, updates, and prerequisites.