RPM Command in Linux | Linuxize

[ad_1]

The RPM Package Manager (RPM) is a powerful package management system used by Red Hat Linux and its derivatives such as CentOS and Fedora. RPM also refers to the rpm command and .rpm file format. An RPM Package consists of an archive of files and metadata including information such as dependencies and install location.

In this tutorial, we will talk about how to use the rpm command to install, update, remove, verify, query, and otherwise manage RPM packages.

Installing, Updating and Removing RPM Packages #

Usually, to install a new package on Red Hat based distributions, you’ll use either yum or dnf commands, which can resolve and install all package dependencies.

You should always prefer using yum or dnf over rpm when installing, updating, and removing packages.

Before installing an RPM package, you must first download the package on your system using a browser or command-line tools like curl
or wget
.

When installing RPM packages
, make sure they are built for your system architecture and your CentOS version
. Be extra careful when replacing or updating important system packages, like glibc, systemd, or other services and libraries that are essential for the proper functioning of your system.

Only root or users with sudo privileges
can install or remove RPM packages.

To install an RPM package with the rpm, use the -i option, followed by the package name:

sudo rpm -ivh package.rpm

The -v option tells rpm to show verbose output and the -h option to show the hash marked progress bar.

You can skip the downloading part and provide the URL to the RPM package to the rpm command:

sudo rpm -ivh https://example.com/package.rpm

To upgrade an RPM package, use the -U option. If the package is not installed it will be installed:

sudo rpm -Uvh package.rpm

If the package you are installing or updating depends on other packages that are not currently installed, rpm will display a list of all missing dependencies. You will have to download and install all dependencies manually.

To install an RPM package without having all the required dependencies installed on the system, use the --nodeps option:

sudo rpm -Uvh --nodeps package.rpm

To remove (erase) an RPM package, use the -e option:

sudo rpm -e package.rpm

The --nodeps option is also useful when you want to remove a package without removing its dependencies:

sudo rpm -evh --nodeps package.rpm

The --test option tells rpm to run of instal­lation or removal command without actually doing anything. It only shows whether the command would work or not:

sudo rpm -Uvh --test package.rpm

Querying RPM Packages #

The -q option tells the rpm command to run a query.

To query (search) whether a certain package is installed, pass the package name to the rpm -q command. The following command will show you whether the OpenJDK 11
package is installed on the system:

sudo rpm -q java-11-openjdk-devel

If the package is installed you will see something like this:

java-11-openjdk-devel-11.0.4.11-0.el8_0.x86_64

Pass -i to get more information about the queried package:

sudo rpm -qi java-11-openjdk-devel

To get a list of all the files in an installed RPM package:

sudo rpm -ql package

If you want to find out which installed package a particular file belongs, type:

sudo rpm -qf /path/to/file

To get a list of all installed packages
on your system use the -a option:

sudo rpm -qa

Verifying RPM Packages #

When verifying a package, the rpm command checks whether each file installed by a package exists on the system, the file’s digest, ownership, permissions, etc.

To verify an installed package, use the -V option. For example, to verify the openldap package you would run:

sudo rpm -V openldap-2.4.46-9.el8.x86_64

If the verification pass the command will not print any output. Otherwise, if some of the checks fail, it will show a character indicates the failed test.

For example, the following output shows that the file’s mTime has been changed (“T”):

.......T.  c /etc/openldap/ldap.conf

Refer to the RMP man page about what each character means.

To verify all the installed rpm packages run the following command:

sudo rpm -Va

Conclusion #

rpm is a low-level command-line tool for installing, querying, verifying, updating, and removing RMP packages. When installing RPM packages should prefer using the yum or dnf as they automatically resolve all dependencies for you.

For more information about all available command options type man rpm in your terminal or visit the RPM.org
website.

If you have any questions or feedback, feel free to leave a comment.

[ad_2]

Source link

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.