Trying to set the default Python version to 2.7, I ran this command:

sudo rm /usr/bin/python*

Now when I type python or python2.7, I see these error messages:

bash: /usr/bin/python: No such file or directory
bash: /usr/bin/python2.7: No such file or directory

What happened? Should I have run the rm command? How can I undo it?

  • 5
    Never remove system files like this. Why did you even consider doing this? Setting the default Python version on your system is not done by removing files, and you should not perform this change. Read this question: Changing Python default for more details. – gertvdijk Dec 28 '12 at 12:37

Well, isn't normal that if you remove an executable, the system can't find it anymore?

/usr/bin/python is a symlink provided by the python-minimal package. You can restore it reinstalling the package:

sudo apt-get install --reinstall python-minimal
  • I tried this,but no change – Muhammad Nov 18 '12 at 17:10
  • @Muhammad Whoops, that file is included in python-minimal – Timo Nov 18 '12 at 18:41
  • @maggotbrain Well, --reinstall reinstalls the package, as the name suggests. You can't just install a package that is already installed, give it a try. – Timo Nov 18 '12 at 18:43

If you have python2.7-minimal (or any of the other variants) installed, you should have the file /usr/bin/python2.7 present. Normally, /usr/bin/python will be symlinked to this file, so that a simple call of python actually ends up running /usr/bin/python2.7.

me@banshee:~$ ls -l /usr/bin/python*
lrwxrwxrwx 1 root root       9 Apr 17  2012 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root       9 Apr 17  2012 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 2989480 Aug  1 01:40 /usr/bin/python2.7

If you do have /usr/bin/python2.7 but you're missing /usr/bin/python, you can simply recreate it from the command line:

you@yourbox:~$ sudo ln -s /usr/bin/python2.7 /usr/bin/python

If you're missing /usr/bin/python2.7, you'll need to reinstall it (again) as proposed by the other answers. Please post back here if that's the case.

  • it appears that I also somehow deleted the usr/bin/python* ....since I am not expert in ubuntu and I don't know how the system works, I had to reinstall the whole system again..hope I will learn from my mistakes..thanks – Muhammad Nov 19 '12 at 1:18

From a terminal, type sudo apt-get install --reinstall python2.7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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