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!
Remove clearly and reinstall python on CentOS
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
@OscarJavierJimenez, I think you have misunderstood this answer. This does not remove the base Python. It reinstalls the base python after it has been removed or replaced, as in the original question. –
Massingill
Yes, you are right, I tried to answer another question in another post. Sorry, it was late. –
Romaromagna
this is probably not a valid solution since the OP mentioned that yum is not working –
Garibaldi
@MayAnneLuyun The reason this answer uses
rpm
instead of yum
is because yum
requires Python, but rpm
does not. –
Massingill To install Python on CentOS: sudo yum install python2/3 (select the version as per requirement) To uninstall Python on CentOS: sudo yum remove python2/3 (select the version as per your requirement) To check version for python3(which you installed): python3 --version To check version for python2 (which you installed): python2 --version
This is not a valid solution because OP indicated they are unable to use yum. –
Heterologous
© 2022 - 2024 — McMap. All rights reserved.
/usr/bin/python
? if so, copy it from another machine – Kelby/usr/bin/python2.6
(in CentOS 6) -- You can try copying that file to/usr/bin/python
assuming you did not overwrite those as well. – Novelize/usr/bin/python
and made a soft link/usr/bin/python
to/usr/bin/python2.7
. I think copying one from another machine would help. – Dora