Install|Remove|Upgrade|Re-Install|Verify|Validate Packages using RPM in Linux


Installing a Package:

rpm -ivh

rpm -ivh httpd-2.4.6-93.el7.centos.x86_64.rpm

Please note if any dependent package is notinstalled it will fail and you have first install the dependent package.

Uninstalling a Package:

rpm -ev

rpm -ev httpd

Please note this will not remove any dependent package that was installed as part of the "httpd" installation.

Upgrading a Package:

rpm -Uvh

To find out which package need to be upgraded we will use below command and all the packages mentioned in bold would be eligible for upgrade.

yum list installed

I ran the command and found below 2 packages.
tzdata.noarch                      
tzdata-java.noarch 

Note: I have already downloaded the rpm.

Now we will upgrade packages, it will cleanup old version and install new rpm.

[root@lcfs packages]# rpm -Uvh tzdata-2020a-1.el7.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:tzdata-2020a-1.el7               ################################# [ 50%]
Cleaning up / removing...
   2:tzdata-2019c-1.el7               ################################# [100%]


In case there is a dependency problem while upgrade which means it create a deadlock like situation where each package is dependent on other then we can use below option while upgrade which will ignore dependency problem.

rpm -Uvh --nodeps

Freshening a Package:

rpm -F

It works same way as upgrade but the diffrence is that it will only upgrade the packages which are already installed, whereas upgrade will install the package if it is not installed.


Re-Installing a Package:

rpm -ivh --force

[root@lcfs packages]# rpm -ivh --force tzdata-2020a-1.el7.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:tzdata-2020a-1.el7               ################################# [100%]


Verify Package Attributes:

Attibutes of a files are
S - Size
M - File permission
5 - Checksum
D - Device Number
L - Link Path
U - User ownership
G - Group ownership
T - Last modified Time
C - Capabilities
c - file type


This will help to identify if the files were changed once they were installed.
This information includes file size, file permissions, check sum, device major and minor numbers, link path, user ownership, group ownership, last modify time, and capabilities. Using rpm verify, we can check if files have changed since they were installed. Rpm verify will also show us the file type. This type could be, a configuration file, a documentation file, a ghost file, which is one where the contents were not included in the package itself, a license file, or lastly, a README file.



rpm -V name

 This shows the size has changed, the digest or check sum has changed, and the last modify timestamp has changed. 
[root@lcfs zoneinfo]# rpm -V yum
S.5....T.  c /etc/yum.conf


We can use "v" to get information in detail

[root@lcfs zoneinfo]# rpm -Vv zip
.........    /usr/bin/zip
.........    /usr/bin/zipcloak
.........    /usr/bin/zipnote
.........    /usr/bin/zipsplit
.........    /usr/share/doc/zip-3.0
.........  d /usr/share/doc/zip-3.0/CHANGES
.........  d /usr/share/doc/zip-3.0/LICENSE
.........  d /usr/share/doc/zip-3.0/README
.........  d /usr/share/doc/zip-3.0/README.CR
.........  d /usr/share/doc/zip-3.0/TODO
.........  d /usr/share/doc/zip-3.0/WHATSNEW
.........  d /usr/share/doc/zip-3.0/WHERE
.........  d /usr/share/doc/zip-3.0/algorith.txt
.........  d /usr/share/man/man1/zip.1.gz
.........  d /usr/share/man/man1/zipcloak.1.gz
.........  d /usr/share/man/man1/zipnote.1.gz
.........  d /usr/share/man/man1/zipsplit.1.gz


To verify all files we can use below command. This is a time taking activity

rpm -Va

Validate Package Integrity

It will help validate if the package is not alter or modified or any type of corruption.

Check MD5 checksum

[root@lcfs packages]# rpm -K --nosignature tzdata-java-2020a-1.el7.noarch.rpm
tzdata-java-2020a-1.el7.noarch.rpm: sha1 md5 OK

GPG check

[root@lcfs packages]# rpm -K  tzdata-java-2020a-1.el7.noarch.rpm
tzdata-java-2020a-1.el7.noarch.rpm: rsa sha1 (md5) pgp md5 OK

Check the key information

[root@lcfs packages]# rpm -q gpg-pubkey
gpg-pubkey-f4a80eb5-53a7ff4b

[root@lcfs packages]# rpm -qi gpg-pubkey-f4a80eb5-53a7ff4b
Name        : gpg-pubkey
Version     : f4a80eb5
Release     : 53a7ff4b
Architecture: (none)
Install Date: Thursday 09 April 2020 08:03:16 AM IST
Group       : Public Keys
Size        : 0
License     : pubkey
Signature   : (none)
Source RPM  : (none)
Build Date  : Monday 23 June 2014 03:49:55 PM IST
Build Host  : localhost
Relocations : (not relocatable)
Packager    : CentOS-7 Key (CentOS 7 Official Signing Key)
Summary     : gpg(CentOS-7 Key (CentOS 7 Official Signing Key) )
Description :