12

I am new to linux and was trying to delete python so I can install it from scratch. Instead of deleting only the python files in /usr/local/bin/ I also deleted these:

/usr/bin/python
/usr/bin/python2.7
/usr/lib/python2.7
/usr/lib64/python2.7
/etc/python
/usr/include/python2.7
/usr/share/man/man1/python.1.gz
/usr/src/Python-3.7.3/python

Now whenever I try to use yum I get:

-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: No such file or directory

Is there a way to fix this or is reinstalling centos7 my only hope?

If it's the latter, how can I do so on a remote server that I have no physical access to?

closed as off-topic by Patrick Mevzek, Gerald Schneider, rvs, b0fh, Jenny D Aug 12 at 12:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – Patrick Mevzek, rvs, b0fh
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 12
    "I am new to linux and was trying to delete python so I can install it from scratch" - Installing Python from scratch is probably the wrong way to go about it anyway; removing your distro-supplied 2.7 is definitely the wrong way. Consider working with your package manager instead of against it. – marcelm Jul 15 at 19:58
  • 4
    This is for Debian, not CentOS, but the advice applies to other distros as well: Don't Break Debian. – Jonathon Reinhart Jul 16 at 0:25
  • 3
    Removing any package that comes from a fresh install (especially if you did a minimal install) brings the risk of breaking the distro. Most linux distros don't come with that much bloat... it's not like Windows10 that comes with candy crush preinstalled or stuff like that. – Giacomo Alzetta Jul 16 at 7:31
  • 4
    Python 2 is used by the system in most versions of linux as a scripting language to automate all sorts of things. By deleting python, you've sawn off the branch you were sitting on. It's probably safest to completely reinstall linux. For a user install of python in linux, it's generally recommended to use a python virtual environment in linux, which keeps the user python completely separate from the system python. It has the advantage that you can install multiple separate python versions, and only need user level, not sudo, to maintain/expand them. – Neil_UK Jul 16 at 9:27
21

You can simply download the packages and install them again with rpm , without having python on your system and a broken yum.

Find the version you had installed

rpm -qf /usr/bin/python

Then find a download URL and either download and install in one go or in separate steps:

rpm --reinstall -v http://mirror.centos.org/centos-7/7/updates/x86_64/Packages/python-2.7.5-80.el7_6.x86_64.rpm
  • Thanks for your answer. I ended up installing Centos on a VM with the same version. And copied all the deleted files over to my server. Yum seems to be working so far but not sure if the damage was fixed entirely. – jdhash Jul 16 at 10:29
  • @jdhash Yum seems to be working so far but not sure if the damage was fixed entirely. And that's just one reason why you never mess around with software installed as part of the OS/distribution. – Andrew Henle Jul 16 at 15:43
  • 1
    I would say that reinstalling the original system is the only way to be sure you've cleaned this up completely. Band-aids like copying files from other systems will keep falling off because the packaging system thinks things are missing, but they're sort of not. The meta data is still not congruent with what's installed. – chicks Jul 17 at 14:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.