Software Installation In Linux Part 3 – rpm In Linux With Examples

In this tutorial, you will learn how to use rpm in Linux for software installation and also learn some other things you can do with rpm.

UNDERSTANDING THE SUBJECT MATTER

Having understood the concept and terminologies of software installation in Linux part 1 and software installation in Linux part 2, it is high time we looked at software installation using rpm in Linux.

Basically, all packages that are installed on RHEL/CentOS uses the rpm database. rpm is a package manager as well as a package file type with the extension “.rpm”

With rpm, you can do a lot with packages even though it’s been replaced with yum. one of the things you can do with rpm is query a package script.

As an administrator, you wouldn’t want to install just any package, especially the ones downloaded from an external repository without verifying it.

It is a good idea to have a look at package scripts. Some packages usually have pre-installation and post-installation scripts.

So one thing you may want to do is to download the package and then run the command which we will be looking at in the “ACTION TIME” section to verify the package so you can be sure the package won’t be harmful to your system.

Red Hat Package browser can also be a very cool way to search and download packages.

In addition, you can also verify an installation script of an already installed package to know if you should uninstall it especially if it will pose a threat or is already a threat to your system.


ACTION TIME

How To Use rpm With Examples

How To Use rpm To Install rpm Package File On RHEL/CentOs 7&8

  • To install a package with the rpm format, you use the command,

rpm -ivh <package>

For example, to install a package “kernel-3.10.0-862.2.3.el7.x86_64.rpm”, you use the command,

[root@lab02 ~]# rpm -ivh kernel-3.10.0-862.2.3.el7.x86_64.rpm


How To Use rpm To Install A Package Without Dependencies On RHEL/CentOS 7&8

  • To install a package without its dependencies, probably the dependencies have been installed but the system doesn’t see it installed, you use the command,

rpm -ivh --nodeps <package>

For example, to install the package “httpd-3.10.0-862.2.3.el7.x86_64.rpm” without it’s dependencies, use the command,

[root@lab02 ~]# rpm -ivh --nodeps  httpd-3.10.0-862.2.3.el7.x86_64.rpm


How To Use rpm To update rpm Package File On RHEL/CentOS 7&8

  • To update a package with the rpm format, you use the command,

rpm -Uvh <package>

For example, to update a package “kernel-3.10.0-862.2.3.el7.x86_64.rpm”, you use the command,

[root@lab02 ~]# rpm -Uvh kernel-3.10.0-862.2.3.el7.x86_64.rpm


How To Use rpm To Delete A Package On RHEL/CentOS 7&8

  • To delete a package with the rpm, you use the command,

rpm -e <package>

For example, to delete a package “kernel-3.10.0-862.2.3.el7.x86_64.rpm”, you use the command,

[root@lab02 ~]# rpm -e kernel-3.10.0-862.2.3.el7.x86_64

OR

[root@lab02 ~]# rpm -e kernel


How To Use rpm To Delete A Package Without Dependencies Checks On RHEL/CentOS 7&8

  • To forcefully remove a package without the system checking its dependencies, you use the command,

rpm -e --nodeps <package>

For example, to remove the package httpd, you use the command,

[root@lab02 ~]# rpm -e --nodeps httpd-3.10.0-862.2.3.el7.x86_64

OR

[root@lab02 ~]# rpm -e --nodeps httpd


rpm in linux

How To Use rpm To Query /List The Document Files Of An Installed Package On RHEL/Centos 7&8

  • To list the document files in a package, you use the command,

rpm -qd <package>

For example, to query the document file of a package lvm2, you use the command,

[root@lab02 ~]# rpm -qd lvm2

/usr/share/doc/lvm2/README
/usr/share/doc/lvm2/VERSION
/usr/share/doc/lvm2/WHATS_NEW
/usr/share/doc/lvm2/lvm_fault_handling.txt
/usr/share/man/man5/lvm.conf.5.gz
/usr/share/man/man7/lvmcache.7.gz
/usr/share/man/man7/lvmraid.7.gz
/usr/share/man/man7/lvmreport.7.gz
/usr/share/man/man7/lvmsystemid.7.gz


How To Use rpm To List All The Files In A Package On RHEL/CentOS 7&8

  • To list all the files in a package, you use the command,
rpm -ql <package>

For example, to list all the files in a package httpd, you use the command,

[root@lab02 ~]# rpm -ql httpd

/etc/httpd/conf
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf


How To Use rpm To Query A File In A Package On RHEL/CentOS 7&8

  • To query a file in a package or to query a file to find out which rpm package the file belongs to, you use the command,

rpm -qf <package>

For example, to query a file “/etc/httpd/conf”, you use the command,

[root@lab02 ~]# rpm -qf /etc/httpd/conf

httpd-2.4.37-16.module+el8.1.0+4134+e6bad0ed.x86_64
[root@lab02 ~]#


How To Use rpm To Query Or List Configuration Files In A Package on RHEL/CentOS 7&8

  • To query or list the configuration files in a package, you use the command,

rpm -qc <package>

For example, to list the configuration files in a package httpd, you use the command,

[root@lab02 ~]# rpm -qc httpd

/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
/etc/httpd/conf.modules.d/00-lua.conf
/etc/httpd/conf.modules.d/00-mpm.conf
/etc/httpd/conf.modules.d/00-optional.conf
/etc/httpd/conf.modules.d/00-proxy.conf
/etc/httpd/conf.modules.d/00-systemd.conf
/etc/httpd/conf.modules.d/01-cgi.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/logrotate.d/httpd
/etc/sysconfig/htcacheclean
[root@lab02 ~]#


How To Use rpm To Query Or Verify All Installed Packages on RHEL/CentOS 7&8

  • To query or verify all installed packages on the system, you use the command,

[root@lab02 ~]# rpm -qa

  • To query or verify all the versions of a specific installed package, for example, kernel package, you use the command,

[root@lab02 ~]# rpm -qa kernel

kernel-4.18.0-80.11.2.el8_0.x86_64
kernel-4.18.0-80.el8.x86_64
[root@lab02 ~]#

[root@lab02 boot]# rpm -qa |grep kernel

kernel-core-4.18.0-80.el8.x86_64
kernel-tools-4.18.0-80.11.2.el8_0.x86_64
kernel-modules-4.18.0-80.el8.x86_64
kernel-modules-4.18.0-80.11.2.el8_0.x86_64
kernel-4.18.0-80.11.2.el8_0.x86_64
kernel-core-4.18.0-80.11.2.el8_0.x86_64
kernel-tools-libs-4.18.0-80.11.2.el8_0.x86_64
kernel-4.18.0-80.el8.x86_64
[root@lab02 boot]#


How To Use rpm To Check For the Installation Script Of A Package That Hasn’t Been Installed On RHEL/CentOs 7&8

  • Not all packages have installation scripts, but for the ones that have and has not been installed, to check for the installation script, you use the command,

rpm -qp --scripts <package>

For example, to check for the installation script of the package, httpd-2.4.37-16.el8.x86_64.rpm, if it hasn’t been installed, you use the command,

[root@lab02 ~]# rpm -qp --scripts httpd-2.4.37-16.el8.x86_64.rpm


How To Use rpm To Check For the Installation Script Of A Package That Has Already Been Installed On RHEL/CentOs 7&8

  • Not all packages have installation scripts, but for the ones that have, to check for the installation script, you use the command,

rpm -q --scripts <package>

For example, to check for the installation script of the package, httpd, you use the command,

[root@lab02 ~]# rpm -q --scripts httpd

postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then
        # Initial installation
        systemctl --no-reload preset httpd.service htcacheclean.service httpd.socket &amp;&gt;/dev/null || :
fi
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then
        # Package removal, not upgrade
        systemctl --no-reload disable --now httpd.service htcacheclean.service httpd.socket &amp;&gt;/dev/null || :
fi
postuninstall scriptlet (using /bin/sh):


# Trigger for conversion from SysV, per guidelines at:
# https://fedoraproject.org/wiki/Packaging:
ScriptletSnippets#Systemd
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || 
  /bin/systemctl try-restart --no-block httpd.service htcacheclean.service &gt;/dev/null 2&gt;&amp;1 || :
[root@lab02 ~]#

There are other great things you can do with rpm in Linux, but the basic ones are the those that I have listed above. As usual, you can also consult the manual page for rpm to get more information on rpm in Linux

Using rpm in Linux to manage packages can also be very useful.

RHCSA Dumps, Q&A On Software Installation In Linux

Your feedback is welcomed. If you love others, you will share with others

Be the first to comment

Leave a Reply

Your email address will not be published.


*