Reinstall RPM Removed in CentOS

RPM Package Manager (RPM) (Red Hat Package Manager) is a powerful command line driven package management system capable of installing, uninstalling, verifying, querying, and updating computer software packages and a core component of many Linux distributions, such as Red Hat Enterprise Linux, the Fedora Project, SUSE Linux Enterprise, openSUSE, CentOS, Tizen, Mageia and many others.


Simply put, RPM, similar to DEB in Ubuntu/Debian, set out to solve the software management problem by packaging metadata, which includes the info of package, the files, scripts and dependencies.

If you delete the rpm by mistake, following this tutorial to recover it.

There are two way to reinstall rpm. The one is compile and install rpm using gcc, that isn’t installed in new linux server commonly.

The other one is copy the related files from a normal machine with the same architecture and Linux distribution. As we known, in Linux System, everything is file. If the missing program is a standalone software or a static binary file, which can run independently without extra library, it will work well by directly copy and run. Otherwise, to coordinate with the related files, you may cost lots of time.

It’s hard to find out all the sparsely related files of rpm in a normal server. However, all the related files are contained in the package of rpm. A rpm package can be partly considered as compressed file, extracted by the rpm2cpio.


Check the architecture and version of target server

Here, I will use Centos 6.8 x86_64 for a example. You should change them in the following steps.

Install a normal server

Running the container images will be faster than creating the traditional virtual machine in another server.

pulling a base library image with the same architecture and version of target server from the mirror repositories for the higher speed.

Create a new Dockerfile to run a simple container.

Build the image from Dockerfile and run in the backgound.

Copy the rpm2cpio

Enter the inside of the running container.

Transfer a rpm2cpio from the normal server to our target server through the Secure copy protocol.

Ctrl+P+Q to return to the normal server. Change to the target server, make the copied rpm2cpio executable.

Reinstall the RPM

Download the rpm package from, choose the correct one for yours.

Extract the files, change the permission and move to root directory.

the symbol {} expands to the filename of each file or directory found with find. The find command means find the directory of the current path and give them 755 permission one by one.
the symbol means stdout, and the tar command means compress three directory to stdout, move to root directory and decompress the three directory from stdout.

Rebuild the cache of package lists and install the rpm.



Leave a Reply

Your email address will not be published. Required fields are marked *