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?

4
  • 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, 2019 at 19:58
  • 4
    This is for Debian, not CentOS, but the advice applies to other distros as well: Don't Break Debian. Jul 16, 2019 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. Jul 16, 2019 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, 2019 at 9:27

1 Answer 1

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:

sudo rpm --reinstall -v https://rpmfind.net/linux/centos/7.8.2003/os/x86_64/Packages/python-2.7.5-88.el7.x86_64.rpm
3
  • 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, 2019 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. Jul 16, 2019 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, 2019 at 14:33

Not the answer you're looking for? Browse other questions tagged .