Skip to content

Instantly share code, notes, and snippets.

@ryandaniels
Last active June 6, 2022 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryandaniels/385ab3dc98677e689c70a5cf8518f6bc to your computer and use it in GitHub Desktop.
Save ryandaniels/385ab3dc98677e689c70a5cf8518f6bc to your computer and use it in GitHub Desktop.
fix CentOS/RHEL duplicate packages

Aborting 'yum upgrade' can cause CentOS7/RHEL7 to have "duplicate packages" installed.

To fix, you could manually run below commands for every affected package (using correct format of package-version or just package name):

rpm -e --justdb --nodeps <package-old_version>
yum reinstall <package>

Or use below commands to avoid manual work.

Bottom of output from:

yum --assumeno upgrade
Warning: RPMDB altered outside of yum.
** Found 247 pre-existing rpmdb problem(s), 'yum check' output follows:
#(truncated)

chkconfig-1.7.4-1.el7.x86_64 is a duplicate with chkconfig-1.7.2-1.el7.x86_64
1:gmp-6.0.0-15.el7.x86_64 is a duplicate with 1:gmp-6.0.0-12.el7_1.x86_64
gobject-introspection-1.50.0-1.el7.x86_64 is a duplicate with gobject-introspection-1.42.0-1.el7.x86_64
grep-2.20-3.el7.x86_64 is a duplicate with grep-2.20-2.el7.x86_64
gzip-1.5-9.el7.x86_64 is a duplicate with gzip-1.5-8.el7.x86_64
pcre-8.32-17.el7.x86_64 is a duplicate with pcre-8.32-15.el7_2.1.x86_64
4:perl-5.16.3-292.el7.x86_64 is a duplicate with 4:perl-5.16.3-291.el7.x86_64
4:perl-libs-5.16.3-292.el7.x86_64 is a duplicate with 4:perl-libs-5.16.3-291.el7.x86_64
4:perl-macros-5.16.3-292.el7.x86_64 is a duplicate with 4:perl-macros-5.16.3-291.el7.x86_64
shared-mime-info-1.8-3.el7.x86_64 is a duplicate with shared-mime-info-1.1-9.el7.x86_64
2:tar-1.26-32.el7.x86_64 is a duplicate with 2:tar-1.26-31.el7.x86_64
#put above package names (starting from packages listed) into:
vi yum-fix.txt

#suggested to run from yum, but doesn't seem to help. maybe it does a bit..
yum-complete-transaction --cleanup-only

cat yum-fix.txt|grep "is a duplicate with" > yum-fix_dupe.txt
cat yum-fix.txt|grep -v "is a duplicate with" > yum-fix_manually.txt

#parse output of some packages that start with a number and colon:
cat yum-fix_dupe.txt |awk '{print $6}'|awk -F":" '{if ((length($1) != 1) && (length($1) != 2)) print $1}' > yum-fix_dupe2.txt
cat yum-fix_dupe.txt |awk '{print $6}'|awk -F":" '{if ((length($1) == 1) || (length($1) == 2)) print $2}' >> yum-fix_dupe2.txt

#remove old package version from rpm db:
for i in $(cat yum-fix_dupe2.txt);do rpm -e --justdb --nodeps $i;done

#remove last 2 columns from output, and put on same line:
#cat yum-fix_dupe2.txt | awk -F"-[0-9]" -vN=2 '{if(NF<N){NF=0}else{NF-=N}print}' |tr '\n' ' ' > yum-fix_dupe2-reinstall.txt
cat yum-fix_dupe2.txt | awk -F"-[0-9]" '{print $1}' |tr '\n' ' ' > yum-fix_dupe2-reinstall.txt

# reinstall packages:
yum reinstall $(cat yum-fix_dupe2-reinstall.txt)

# don't forget to go back and manually fix the non-duplicates
# above could have fixed them.. try yum upgrade to see if any more errors):
cat yum-fix_manually.txt

yum --assumeno upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment