Home > centos/rhel, how to, linux > How-To: Reinstall rpm and yum without rpm/yum in CentOS/RHEL

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, [www.thedumbterminal.co.uk] 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 http://vault.centos.org/4.1/os/i386/CentOS/RPMS/rpm-4.3.3-9_nonptl.i386.rpm
$ 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 http://vault.centos.org/4.1/os/i386/CentOS/RPMS/yum-2.2.1-1.centos4.noarch.rpm
$ wget -c http://vault.centos.org/4.1/os/i386/CentOS/RPMS/rpm-python-4.3.3-9_nonptl.i386.rpm
$ 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 :)

Categories: centos/rhel, how to, linux Tags: , , ,
  1. Vasyl
    December 24, 2010 at 5:58 am | #1

    Huh ) Pretty tricky! U’ve saved my life man!

  2. winnieee
    March 11, 2011 at 1:43 pm | #2

    dude…you rock…you saved my time…i never found this information anywhere…luv u! :D

  3. June 21, 2011 at 5:07 pm | #3

    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: librpm-4.3.so: 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!!!

    Thanks

    • tar
      June 28, 2011 at 7:15 am | #4

      Hi Ian. Did you manage to fix it? What rpm package did you download?

  4. jason
    March 3, 2012 at 8:03 pm | #5

    Dude,

    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…

  1. April 19, 2012 at 3:19 pm | #1

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 427 other followers