RPM (RedHat Package Manager) is the default package manager for RedHat & for many other Linux distributions based on it like CentOS, Oracle Linux, and Amazon Linux among others.
RPM is used for processing the packages with .rpm extension, we can install, uninstall, upgrade .rpm packages with RPM. RPM maintains a database of installed packages which allows us to query information regarding packages and such.
Recommended Read: Important POSTGRESQL commands you should know
Also Read: Scheduling CRON Jobs with Crontab for Beginners
In this tutorial, we will learn to use the RPM command in Linux with some examples.
The syntax for using rpm command in Linux:-
# rpm -(options) package_name
Now let’s discuss some examples so that we have a better understanding.
Examples of rpm
– Installing an rpm package
To install a package, we will use the following command,
# rpm –ivh packge_name.rpm
Here, -i options is for installing a package, -v is for verbose (additional details of what’s being done), -h is for showing percentage completion with # markings.
We can also use the rpm command with upgrade option to install a package
# rpm -Uvh fuse-ntfs-3g-2013.1.13-2.el7.rf.x86_64.rpm
– Upgrade an rpm package
To upgrade an already installed package, use ‘U’ option with rpm common,
# rpm –Uvh fuse-ntfs-3g-2013.1.13-2.el7.rf.x86_64.rpm
– Removing a package
To remove a package, use rpm command with option ‘e’,
# rpm –evh httpd
– Checking if a package is installed or not
To check whether a package has been installed or not, we can query the package with option ‘q’,
# rpm –q httpd
– List all the files for a package
To check the list of all the files for installed rpm packages, use the option ‘l’ with ‘q’,
# rpm –ql httpd
– Checking dependencies before installing
To install a rpm package, all dependencies must be installed first. We can check the list of dependencies for a package with the following command,
# rpm –qpR httpd-2.4.6-2-45.el7.centos.x86_64.rpm
Option ‘p’ provides the functionality provided package, ‘R’ provides the dependencies for the package.
– Installing rpm without dependencies
Though all the dependencies are required to be installed before we can install & use a package. We can also install a package without installing dependencies (whether it will work or not is another story),
# rpm –ivh –nodeps httpd-2.4.6-2-45.el7.centos.x86_64.rpm
‘-nodeps’ is what allows us to install a package without dependencies. The same option can also be used to uninstall a package without dependencies,
# rpm –evh –nodeps httpd
– List all installed packages
Check the list of all installed packages using the following command,
# rpm –qa
We can also check recently installed packages with the above-mentioned command by just adding ‘–last’ option in the end,
# rpm -qa –last
– List info about a single package
To get information about an installed package, use
# rpm –qi perl
If we need the package information without installing it, we can use the following command,
# rpm -qip httpd-2.4.6-2-45.el7.centos.x86_64.rpm
– Checking which file belongs to which package
If we need to find out which files belong to which package, we will use the following command,
# rpm –qf /var/log/httpd
– Verify package
To verify a single package against the rpm database, use
# rpm –Vp httpd-2.4.6-2-45.el7.centos.x86_64.rpm
To verify all the installed package on the system, use
# rpm -Va
This was our tutorial on how to use rpm command in Linux, please feel free to send in any questions or queries using the comment box below.