How to fix duplicate packages in yum

- by

From time to time, the yum package manager may encounter issues with duplicate packages that are erroneously installed on a system. This manifests in a yum update going awry, telling us something along the lines of this:

yum update
...
--> Finished Dependency Resolution
Error: Package: ntp-4.2.6p5-22.el7.centos.2.x86_64 (@updates)
           Requires: ntpdate = 4.2.6p5-22.el7.centos.2
           Removing: ntpdate-4.2.6p5-22.el7.centos.2.x86_64 (@updates)
               ntpdate = 4.2.6p5-22.el7.centos.2
           Updated By: ntpdate-4.2.6p5-25.el7.centos.x86_64 (base)
               ntpdate = 4.2.6p5-25.el7.centos
 You could try using --skip-broken to work around the problem
** Found 41 pre-existing rpmdb problem(s), 'yum check' output follows:
// huge scary list of packages follows

You may at times install all other packages via yum update –skip-broken, but it will still leave some trouble on the system. Best to take care of it.

Here’s how I’ve managed to do it on many occasions:

Installing yum-utils

The utility that will help us fix these issues is called package-cleanup, and it’s part of the yum-utils package. Let’s install that first before we continue:

yum install yum-utils

Next, let’s see what’s wrong with our system. package-cleanup –dupes will show us duplicate packages on the system:

package-cleanup --dupes

Loaded plugins: fastestmirror
parted-3.1-23.el7.x86_64
parted-3.1-28.el7.x86_64
tar-1.26-31.el7.x86_64
tar-1.26-29.el7.x86_64
lvm2-2.02.130-5.el7_2.5.x86_64
lvm2-2.02.166-1.el7_3.1.x86_64
...

The list could go on. Here we see that several packages are seemingly installed more than once. The –cleandupes parameter will take care of this, erasing such superfluous packages:

package-cleanup --cleandupes

The process will look very similar to a yum update, with yum verifying and erasing the duplicates. It doesn’t hurt to make a note of the erased packages and check if the latest version is still installed. Should this not be the case, you can bring those packages back with “yum reinstall packagename”.

Finishing Up

At this point, let’s try to update the system again with a standard yum update command. This should take care of any missing dependencies that may have been removed in the previous process, and of course it’ll update the rest of your system too, hopefully taking care of the initial problem.

yum update

Finally, to see if there’s any remaining trouble with the yum database, we can issue the following and are – hopefully – greeted with the same message:

package-cleanup --problems

Loaded plugins: fastestmirror
No Problems Found


If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

7 thoughts on “How to fix duplicate packages in yum”

  1. [root@ubuntu ~]# package-cleanup -cleandupes
    CRITICAL:yum.verbose.cli.packagecleanup:Config Error: Error accessing file for config file:///root/leandupes

  2. This is not a useful explanation. Is this command going to remove just the extra entry from the rpm database, OR will this actually attempt to uninstall the package and the files that belong to it? Two very different things. The second could be disasterous.

  3. I thought when I wrote “the duplicate package is removed” it was quite clear that the package is not uninstalled… only the duplicate is. Shame it didn’t help you, but for me it works time and time again when this problem arises on CentOS.

  4. Thanks for the information above. And this solves my problem described below:

    I have the situation that the server is experiencing problems with duplicate packages in the Yum update.
    How to solve this in a way that does not have to cause a stop, or that causes a problem in the server, since it is an internet server, proxy and email …
    Until I found something, but they are very old postings, so I am in doubt if they still apply to the current version of CentOS 7.5.1804 and there is no information if it can cause a problem if I have the risk of removing some package and or configuration in use, and cause the system shutdown, or other serious problem.

    Here’s the situation in .txt file in Google Drive: https://drive.google.com/file/d/18YqqmqX5neEhXSIcVWc-hpsb-v7qN2UM/

    Thanks in advance.

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.