How to remove package from rpm database

Roy Hinkley asked:

I have a Centos 6 server that I accidentally added a RHEL 7 package to it’s rpm database.

Added wrong package

sudo rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm

So when I tried to add the correct package I get:

sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.rzDcOd: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
    file /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX from install of zabbix-release-3.2-1.el6.noarch conflicts with file from package zabbix-release-3.0-1.el7.noarch
    file /etc/yum.repos.d/zabbix.repo from install of zabbix-release-3.2-1.el6.noarch conflicts with file from package zabbix-release-3.0-1.el7.noarch

So I ran the following:

yum clean all
rpm --rebuilddb

Then added RHEL 6 package:

sudo rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/6/x86_64/zabbix-release-3.2-1.el6.noarch.rpm
warning: /var/tmp/rpm-tmp.DgETOM: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing...                ########################################### [100%]
   1:zabbix-release         ########################################### [100%]

But install still reverts back to wrong package:

sudo yum install zabbix-agent
Loaded plugins: fastestmirror, presto, refresh-packagekit
Setting up Install Process
Determining fastest mirrors
epel/metalink                                                                                                                                                                      |  18 kB     00:00     
 * base: repos-va.psychz.net
 * epel: mirror.vcu.edu
 * extras: centos.mirror.constant.com
 * fasttrack: mirror.fileplanet.com
 * updates: mirror.fileplanet.com
base                                                                                                                                                                               | 3.7 kB     00:00     
base/primary_db                                                                                                                                                                    | 4.7 MB     00:01     
centos-sclo-rh                                                                                                                                                                     | 2.9 kB     00:00     
centos-sclo-rh/primary_db                                                                                                                                                          | 1.2 MB     00:00     
centos-sclo-sclo                                                                                                                                                                   | 2.9 kB     00:00     
centos-sclo-sclo/primary_db                                                                                                                                                        | 154 kB     00:00     
cr                                                                                                                                                                                 | 3.3 kB     00:00     
cr/primary_db                                                                                                                                                                      | 1.2 kB     00:00     
epel                                                                                                                                                                               | 4.7 kB     00:00     
epel/primary_db                                                                                                                                                                    | 6.0 MB     00:02     
extras                                                                                                                                                                             | 3.4 kB     00:00     
extras/primary_db                                                                                                                                                                  |  27 kB     00:00     
fasttrack                                                                                                                                                                          | 2.9 kB     00:00     
fasttrack/primary_db                                                                                                                                                               | 9.9 kB     00:00     
updates                                                                                                                                                                            | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                 | 3.0 MB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package zabbix-agent.x86_64 0:3.0.24-1.el7 will be installed
--> Processing Dependency: libc.so.6(GLIBC_2.17)(64bit) for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: systemd
 You could try using --skip-broken to work around the problem
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
libmodule-10.0.1.274-b10_0_1_274.x86_64 has missing requires of libodbc.so.1()(64bit)
[[email protected] ~]# sudo rpm -evh zabbix-release-3.0-1.el7.noarch
rpm: --hash (-h) may only be specified during package installation
[[email protected] ~]# sudo rpm -ev zabbix-release-3.0-1.el7.noarch
error: package zabbix-release-3.0-1.el7.noarch is not installed

So I tried to explicitly remove package:

sudo rpm -ev zabbix-release-3.0-1.el7.noarch
error: package zabbix-release-3.0-1.el7.noarch is not installed

How do I run YUM install to use RHEL 6 package or remove RHEL 7 package from rpm db?

Edit

So I ran the following per suggestion:

rpm -e zabbix-release

Which appears to have executed without error.

I don’t know which packages are part of my distro:

ls -all /etc/yum.repos.d 
total 68 
drwxr-xr-x.   2 root root  4096 Jan 23 13:43 . drwxr-xr-x. 117 root root 12288 Jan 23 11:37 ..
-rw-r--r--.   1 root root  1991 Jun 26  2018 CentOS-Base.repo
-rw-r--r--.   1 root root   509 Sep 25  2011 CentOS-CR.repo
-rw-r--r--.   1 root root   647 Jun 26  2018 CentOS-Debuginfo.repo
-rw-r--r--.   1 root root   276 May 12  2014 CentOS-fasttrack.repo
-rw-r--r--.   1 root root   289 Aug  3  2015 CentOS-fasttrack.repo.rpmnew
-rw-r--r--.   1 root root   630 Jun 26  2018 CentOS-Media.repo
-rw-r--r--.   1 root root   916 May 23  2016 CentOS-SCLo-scl.repo
-rw-r--r--.   1 root root   892 Jun 16  2016 CentOS-SCLo-scl-rh.repo
-rw-r--r--.   1 root root  8854 Jun 26  2018 CentOS-Vault.repo
-rw-r--r--.   1 root root   954 Oct  3  2016 epel.repo
-rw-r--r--.   1 root root  1056 Nov  4  2012 epel-testing.repo

Edit 2

Yum is still trying to use the wrong package

sudo yum install zabbix-agent
Loaded plugins: fastestmirror, presto, refresh-packagekit
Setting up Install Process
Determining fastest mirrors
 * base: mirror.vcu.edu
 * extras: mirrors.greenmountainaccess.net
 * fasttrack: packages.oit.ncsu.edu
 * updates: mirror.cisp.com
base                                                                                                                                                                               | 3.7 kB     00:00     
base/primary_db                                                                                                                                                                    | 4.7 MB     00:02     
centos-sclo-rh                                                                                                                                                                     | 2.9 kB     00:00     
centos-sclo-rh/primary_db                                                                                                                                                          | 1.2 MB     00:02     
centos-sclo-sclo                                                                                                                                                                   | 2.9 kB     00:00     
centos-sclo-sclo/primary_db                                                                                                                                                        | 154 kB     00:00     
cr                                                                                                                                                                                 | 3.3 kB     00:00     
cr/primary_db                                                                                                                                                                      | 1.2 kB     00:00     
extras                                                                                                                                                                             | 3.4 kB     00:00     
extras/primary_db                                                                                                                                                                  |  27 kB     00:00     
fasttrack                                                                                                                                                                          | 2.9 kB     00:00     
fasttrack/primary_db                                                                                                                                                               | 9.9 kB     00:00     
updates                                                                                                                                                                            | 3.4 kB     00:00     
updates/primary_db                                                                                                                                                                 | 3.0 MB     00:01     
Resolving Dependencies
--> Running transaction check
---> Package zabbix-agent.x86_64 0:3.0.24-1.el7 will be installed
--> Processing Dependency: libc.so.6(GLIBC_2.17)(64bit) for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Processing Dependency: systemd for package: zabbix-agent-3.0.24-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: libc.so.6(GLIBC_2.17)(64bit)
Error: Package: zabbix-agent-3.0.24-1.el7.x86_64 (zabbix)
           Requires: systemd
 You could try using --skip-broken to work around the problem
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
libmodule-10.0.1.274-b10_0_1_274.x86_64 has missing requires of libodbc.so.1()(64bit)

In particular

---> Package zabbix-agent.x86_64 0:3.0.24-1.el7 will be installed

My answer:


You need to uninstall the incorrectly installed package, i.e.:

rpm -e zabbix-release

You remove packages by package name, not by filename, because installed packages don’t have a filename.


Of course, this probably won’t fix the problem, because you destroyed and rebuilt the RPM database when there was no need to do so, and it is likely there are files the wrong package installed that are no longer tracked. You will need to find these and remove them manually. Look in the /etc/yum.repos.d directory and find repo files which don’t correspond to your distribution. Or you might get lucky and the files get cleaned out OK.


Once that’s done, you need to clean yum’s caches with yum clean all and then reinstall the correct zabbix-release RPM.


View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.