Repair duplicate rpm package is not an easy task. In this post we will learn on how to repair duplicate rpm in Centos system. Before this we have learn how to recover wrongly set permission on Centos 7.
Recently I have encounter problem with duplicate rpm issue in one of my server using Centos. The problem was caused by sudden server reboot during yum update. This cause server to have multiple duplicate rpm across the system.
We cannot continue to run the yum update because stuck at the following error example below;
. . . 1:ea-php73-php-pdo-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-pdo-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-pgsql-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-pgsql-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-posix-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-posix-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-process-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-process-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-pspell-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-pspell-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-soap-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-soap-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-sockets-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-sockets-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-xml-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-xml-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-xmlrpc-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-xmlrpc-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-php-zip-7.3.13-1.el7.cloudlinux.1.x86_64 is a duplicate with 1:ea-php73-php-zip-7.3.11-1.el7.cloudlinux.x86_64 1:ea-php73-runtime-7.3.13-1.el7.cloudlinux.x86_64 is a duplicate with 1:ea-php73-runtime-7.3.11-1.el7.cloudlinux.x86_64 . . .
To check the list of the duplication use command below;
# package-cleanup --dupes . . . ea-php53-php-pdo-5.3.29-29.el7.cloudlinux.14.x86_64 ea-php53-php-pdo-5.3.29-29.el7.cloudlinux.15.x86_64 ea-php72-php-pdo-7.2.26-1.el7.cloudlinux.1.x86_64 ea-php72-php-pdo-7.2.24-1.el7.cloudlinux.x86_64 ea-php72-php-curl-7.2.24-1.el7.cloudlinux.x86_64 ea-php72-php-curl-7.2.26-1.el7.cloudlinux.1.x86_64
Use below command to write to file what is the list of the duplicate files;
#package-cleanup --dupes | tail -n +3 > duplicate.txt
Using ‘cat’ command to read the list.
The idea is to remove the lowest version of the package from rpm database (rpmdb).
Then reinstall back the highest version of the package.
The command should be like;
rpm -e --justdb --nodeps PKGNAME yum -y reinstall PKGNAME
Example ;
rpm -e --justdb --nodeps ea-nghttp2-1.39.2-1.el7.cloudlinux.1.x86_64 yum -y reinstall ea-nghttp2
It is the best to check the command before real operation;
cat duplicate.txt | sort --version-sort | awk 'NR % 2 {print "rpm -e --justdb --nodeps " $1 } !(NR % 2) {match($0, "-[0-9]");print "yum -y reinstall " substr($0,0,RSTART-1)}'
Also can write the command to file;
cat duplicate.txt | sort --version-sort | awk 'NR % 2 {print "rpm -e --justdb --nodeps " $1 } !(NR % 2) {match($0, "-[0-9]");print "yum -y reinstall " substr($0,0,RSTART-1)}' > reinstall.txt
The content of the reinstall.txt file will be similar like ;
. . . rpm -e --justdb --nodeps ea-php73-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73 rpm -e --justdb --nodeps ea-php73-php-bcmath-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-bcmath rpm -e --justdb --nodeps ea-php73-php-bz2-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-bz2 rpm -e --justdb --nodeps ea-php73-php-cli-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-cli rpm -e --justdb --nodeps ea-php73-php-common-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-common rpm -e --justdb --nodeps ea-php73-php-curl-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-curl rpm -e --justdb --nodeps ea-php73-php-dba-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-dba rpm -e --justdb --nodeps ea-php73-php-devel-7.3.11-1.el7.cloudlinux.x86_64 yum -y reinstall ea-php73-php-devel . . .
Download duplicate.txt and reinstall.txt if required. reinstall.txt is useful if we want to install high priority package manually. Manual install is the most recommended way if there are not to many duplicate and you are not an expert system admin.
Wrongly remove package can render your server unbootable of problem with multilib issue.
If you know what are you doing then you can just run below command to repair duplicate rpm.
cat duplicate.txt | sort --version-sort | awk 'NR % 2 {print "rpm -e --justdb --nodeps " $1 } !(NR % 2) {match($0, "-[0-9]");print "yum -y reinstall " substr($0,0,RSTART-1)}' | sh