How-To: Reinstall rpm and yum without rpm/yum in CentOS/RHEL

We were trying to reinstall the Munin package last week in one of our production servers and I somehow managed to screw things up. I accidentally removed rpm (and since yum depends on it, it was removed also!). And since yum and rpm are now gone, we can’t install anything! Cr*p!

Desperate times indeed. Luckily, Google search somehow pointed me in the right direction. I stumbled on this site, [] and it gave me the answer that I was looking for 🙂

NOTE: Check first if what version of CentOS do you have and what architecture. URLs must be changed if you’re not using CentOS 4.1

These are the commands that I executed in shell:
$ mkdir /tmp/install && cd /tmp/install
$ wget -c
$ rpm2cpio rpm-4.3.3-9_nonptl.i386.rpm | cpio -dim
$ find . -type d -exec chmod 755 {} \;
$ tar cf - ./usr ./etc ./bin | (cd /; tar xvf -)
$ rpm --rebuilddb
$ rpm -i rpm-4.3.3-9_nonptl.i386.rpm

In the last line (above), rpm has to be re-installed to update the package version in CentOS db. rpm won’t install a .rpm package otherwise. You have to copy the rpm2cpio command from other existing CentOS/RHEL installations if you can’t find/run it.

To re-install yum, I ran these commands:
$ wget -c
$ wget -c
$ rpm -i rpm-python-4.3.3-9_nonptl.i386.rpm
$ rpm -i yum-2.2.1-1.centos4.noarch.rpm

And that’s how I cleaned-up my mess. And yes, the server is running CentOS 4.1 🙂

11 thoughts on “How-To: Reinstall rpm and yum without rpm/yum in CentOS/RHEL

  1. Ian Roberts

    Not sure what’s happening here, but I follow the steps happily until I get to rpm –rebuild – I get this error:

    rpm: error while loading shared libraries: cannot open shared object file: No such file or directory

    This is causing me a major stress now and don’t know what to do! I’m on CentOS 5.5 (though for some reason after this, it told me I was now using 5.6).

    Any help will be greatly appreciated as yum is currently rendered useless!!!


  2. jason


    same issue I have no rpm as well no yum….following the steps over here but how do i copy rpm2cpio from another machine and how do I run on this machine …I have Centos 5.2…

  3. Pingback: Centos 5 Error :- -bash: yum: command not found - Page 4

  4. Jacky 4

    i get the same issue as Ian..rpm: error while loading shared libraries: cannot open shared object file: No such file or directory

    am using rpm- for my CentOS 5.8..
    any idea how to fix this?

    1. tar Post author

      Hi Jacky,

      I don’t think I encountered that error before. A lot has changed from CentOS 4 to 5. Did you try copying the needed libraries from other 5.x servers?

      Good luck!

  5. Pingback: rpm2cpio: command not found & RPM/YUM deleted accidentally « I haven't yet decided on the title

  6. kiranchitturi


    I messed up my OS and removed rpm, yum, rpmlibs. This made me desperate in searching for solution and i am not able to fix it. I came across your post and did everything similar in centos 6 but when i do ‘sudo rpm -i rpm-4.8.0-12.el6.x86_64.rpm ‘, i get

    warning: rpm-4.8.0-12.el6.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
    error: Failed dependencies: is needed by rpm-4.8.0-12.el6.x86_64 is needed by rpm-4.8.0-12.el6.x86_64 is needed by rpm-4.8.0-12.el6.x86_64

    I copied those above files, but it keeps saying failed dependencies. Is there any way i can fix this too, so i can install rpm and work on things ?

    Are dependencies read from the database files ? Do you know any way to show that these dependencies are present already ?

    Please let me know if you have any kind of suggestion. Its a messy thing to remove rpm, yum. Sucks.

    Thank for the post though, it helped almost to fix my error.


    1. tar Post author

      Hi Kiran,

      I think a lot has changed since CentOS 4 to 6. I’m not sure how to fix this in CentOS 6. If you have another server running the same OS, have you tried copying the needed files manually? HTH.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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