Accidentally deleted python and yum is not working in centos7

10,067

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
Share:
10,067

Related videos on Youtube

jdhash
Author by

jdhash

Updated on September 18, 2022

Comments

  • jdhash
    jdhash over 1 year

    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?

    • marcelm
      marcelm almost 5 years
      "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.
    • Jonathon Reinhart
      Jonathon Reinhart almost 5 years
      This is for Debian, not CentOS, but the advice applies to other distros as well: Don't Break Debian.
    • Giacomo Alzetta
      Giacomo Alzetta almost 5 years
      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.
    • Neil_UK
      Neil_UK almost 5 years
      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.
  • jdhash
    jdhash almost 5 years
    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.
  • Andrew Henle
    Andrew Henle almost 5 years
    @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.
  • chicks
    chicks almost 5 years
    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.