Issue
Today I messed up the versions of Python on my CentOS machine. Even yum
cannot work properly. I made the mistake that I removed the default /usr/bin/python
which led to this situation. How could I get back a clear Python environment? I thought remove them totally and reinstall Python may work, but do not know how to do it. Wish somebody could help!
Solution
The yum
package manager is relies on an underlying tool called rpm
, which does not require Python. You can use that to re-install the system Python package.
You can use this to reinstall the base python
package from a CentOS mirror:
rpm -ivh --replacepkgs --replacefiles http://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
For example:
# rm -f /usr/bin/python*
# yum version
bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory
# rpm -ivh --replacefiles --replacepkgs http://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
Retrieving http://mirror.centos.org/centos/6/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
warning: /var/tmp/rpm-tmp.DCR7QF: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:python ########################################### [100%]
# yum version
Loaded plugins: fastestmirror, ovl
Installed: 6/x86_64 131:0e17bede37a026e5f95d6cb7e185701b989fa47d
Group-Installed: yum 14:973b685dc3deb5d8f00cdb3ec97022064b5ff793
version
Answered By - larsks Answer Checked By - Candace Johnson (WPSolving Volunteer)