If you have been looking to learn how to use the RPM command in Linux OS, here’s everything you need to know.
RPM command is a command line utility for installing packages in Red Hat-based systems. We will start with a brief overview of RPM. Then, we will discuss the steps for installation, upgrading, removing, querying, and verifying RPM packages.
To follow the article on how to use the RPM command in Linux, you should have a system with Linux OS installed. Then, you can open your terminal from the system menu and select terminal. You should have access to the root user or a user with sudo privileges.
Note: RPM is a low-level package management utility. Using YUM or DNF instead is recommended, as they automatically deal with dependencies.
What is RPM?
RPM is one of the most widely used utilities for installing software in Linux. An RPM package comprises an archive of files and metadata. The metadata includes the details of the dependencies and the install location. RPM has the following features:
- It is a command-line utility for managing packages in the Linux system.
- It can be used to install, update, query, or remove packages from the system.
- It is the default package manager for Red hat based systems. It is also used in CentOS and Fedora.
- It uses the file with the
.RPM
extension.
How to Use the RPM Command in Linux
The basic usage of an RPM command is as follows:
sudo RPM [option] [package_name]
To see the full list of RPM commands, type the following on your terminal:
sudo RPM --help
You should see the following screen:
Installing software in Linux using RPM
We will now briefly discuss how to use the RPM command in Linux to install a package. Follow the steps below to install an RPM package.
Log in as the root user
The first step is to log in as the root user. You can also use the su
command to switch the user to root.
Download the package
The next step is to download the package you wish to install. The name of the package will be something like software.RPM
Install the package
After downloading the package, you can easily install it with the help of the following command:
$RPM –i software.RPM
Suppose, you want to install the MySQL package, then you can use the following command:
sudo RPM -ivh mysql80-community-release-el7-5.noarch.RPM
Here, the “i
” stands for installation, “v
” is for verbose, and “h
” is for printing hash marks to show installation.
Upgrading a package
In case you are upgrading to an older version, you can run the RPM in upgrade mode as follows:
#npm –U software.RPM
For instance, you can upgrade the MySQL server with the help of the following command:
$sudo RPM -Uvh mysql80-community-release-el7-5.noarch.RPM
Note that if the newer version requires dependencies, they must be installed manually. After running the command, RPM will list the dependencies as output. To ignore the message and install the package without dependencies, you can use the following command:
$sudo RPM -Uvh --nodeps package_name
Here, the nodeps flag tells RPM to ignore the dependencies.
Installing an RPM package which is not previously been downloaded
You can install a package that is not previously downloaded with the help of the following command:
$sudo RPM -ivh package_URL
For instance, the MySQL package can be downloaded with the help of the following command:
$sudo RPM -ivh https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.RPM
Removing an RPM package
We will now discuss the process of removing an RPM package. In particular, the package can be removed with or without its dependencies, and both approaches are discussed below.
Removing an RPM package
To remove an RPM package, you can use the –e (–erase option) as follows:
$sudo RPM -e package_name
You can also use the –v option to see the verbose output.
$sudo RPM -ev package_name
Removing an RPM package without removing dependencies
To remove an RPM package without removing dependencies, use the following command:
$sudo RPM -ev --nodeps package_name
For instance, you can remove MySQL without removing any related dependencies as follows:
$sudo RPM -ev --nodeps mysql80-community-release-el7-5.noarch
Querying RPM packages
The –q
option is used for querying RPM packages. The following paragraph briefly discusses how we can query RPM packages in various ways.
Querying if a package is installed or not
For instance, the following command can be used to query if JDK is installed on your system or not:
$sudo RPM -q java-11-openjdk-devel
Getting more information about the queried package
To get more information about the queried package, you can use the following command:
$sudo RPM -qi java-11-openjdk-devel
Getting the list of files installed for a package
To obtain information about the list of files installed for a package, use the following command:
$sudo RPM -ql package
Verifying RPM packages
Finally, we can also verify installed RPM packages. Follow the steps below to verify RPM packages in various ways.
Verifying an installed package
To verify an installed package, you can use the –V command:
$sudo RPM -V openldap-2.4.46-9.el8.x86_64
You may see the information if the verification has failed.
Verify all the installed RPM packages
To verify all the installed RPM packages, you can use the following command:
$sudo RPM –Va
In this article, we have discussed RPM and how to use the RPM command in Linux, along with upgrading, removing, querying, and verifying RPM packages. There are several flags we can use with RPM, such as:
–e for erase.
-h for hash.
-i for install.
-l for list.
-q for query.
-s for state.
-U for upgrade.
-v for verbose.
–V for verify.
We have briefly discussed some of these options. For more details, you can refer to the manual.
If this guide helped you, please share it.