I have installed Python 2.7.9 in /usr/local/bin
. Now it doesn't work any more. I have another Python in /usr/bin/
but in the path is /usr/local/bin/
first. How can i remove the 2.7.9 Python?
-
No bin sorry. I wrote it wrong – Velrest May 21 '15 at 08:34
-
5Do something like "$export PATH=/usr/bin:$PATH". Then it should be fine. But this is if you are using bash shell. Something else you may have to on other shells. – Nipun Talukdar May 21 '15 at 08:35
-
3you can do something brutal like:sudo rm -rf /usr/local/bin/python or simply rename it? – Amir H May 21 '15 at 08:55
-
4@AmirH The installation probably comprises a large number of library files as well. Whatever installed the package ought to know what exactly it created and where; without that information, we can't really help, only speculate. – tripleee May 21 '15 at 09:10
-
@AmirH It works. `which python` is now /bin/usr/python. Thank you – Velrest May 21 '15 at 09:13
4 Answers
Your question is lacking in details, the most pertinent being how you actually installed Python into /usr/local/bin
. The installation method would indicate how to remove the installed files.
The most common way of installing packages into the /usr/local
hierarchy of directories to is to compile from source and to run sudo make install
after compiling and linking. If you didn't already remove the original (uncompressed) source directory, you can change into it and remove the compiled Python package by running:
sudo make uninstall
If the source code has been deleted, you could try re-downloading the source again.
If there’s no uninstall
target for make
(unfortunately, more common than you might think), another (inelegant) option is to use the find
command to search for all files in /usr/local
directory tree that have the same modification time as other files in the application that you want to remove.
These days, I would recommend installing the checkinstall
tool. Instead of running make install
, this can be used to create an RPM or Debian package which can then be installed (and uninstalled) using the system’s regular software installation tools.

- 11,533
- 5
- 49
- 56
-
There are also package managers like Homebrew on MacOS which install into `/usr/local` -- obviously, use the package manager's package removal functionality if that's how you installed the package in the first place. – tripleee Aug 13 '17 at 13:25
-
-
@MianAsbatAhmad That's much trickier. You could try re-downloading the source again. Another option is to use the `find` command to search for all files in `/usr/local` that have the same modification time as the executable that I want to remove. These days I use the `checkinstall` tool to create an RPM or Debian package and then install that package instead of running `make install`. – Anthony Geoghegan Sep 13 '17 at 13:31
DISCLAIMER: I've since learned a lot, and would recommend setting environment variables for a shell or shell session rather than use this answer. For example, if you manually relink the system's Python2 interpreter to a Python3 interpreter, you may wreak havoc on your system. Please use this answer with caution.
Just reset the symlink.
First, find out which python:
$ which python
In my case, I get:
/usr/local/bin/python
Then find where the symlink points to
$ file /usr/local/bin/python
/usr/local/bin/python: symbolic link to `/usr/bin/python'
Then just repoint the symlink back to the default (in this case, I use the default: /usr/bin/python).
No uninstalls necessary.
Update
I've since found a lot of better ways to enact this exact same behavior, without having effects on the entire system.
Say I have an undesired python
install in /usr/bin
, and a desired python
install in /opt/bin
. Let's say for the point of comparison that the /usr/bin
is Python 3.5, and the /opt/bin
is Python 2.7. This would create immediate consequences for using the wrong Python interpreter, rather than subtle errors down the line.
Application Defaults
If you would like to (on Linux systems) change which interpeter runs Python scripts, you can change this either via a GUI, or via xdg-mime (a walkthrough can be found here). For macOS or Windows, this can be done easily through a GUI.
Interactive Shell
If you would like to change the default Python for a specific shell, I can see two good ways of doing this. One would be to change the default search PATH
to set /opt/bin
before usr/bin
for a specific situation, however, if you have numerous alternative installs to system packages, this might pose issues too. Another would be to set an alias for Python to the version you want to use. This is the preferred solution, as it only changes the interpreter and is merely a shortcut to reference an existing command.
For example, to set the alias I could use:
alias python="/opt/bin/python"
And to change the default path, I could use:
export PATH=/opt/bin:$PATH
Adding these lines to ~/.bashrc
or ~/.bash_aliases
(the latter is Ubuntu-only by default) will make these shortcuts be the default on any interactive shell you start. Combining application defaults and interactive shell scripting allows you to have tight control over which interpreter runs your code, but does not require interfering with potentially crucial system files.

- 13,272
- 3
- 39
- 67
Your PATH environment variable. It has a list of directories which bash searches (in the same order) when it's looking for an program to execute. Basically you want to put /usr/local/bin at the start of your PATH environment variable. Add the following to your ~/.bashrc file:
export PATH=/usr/local/bin:$PATH
You can have a look at the current setting by running the set command in bash.
Alternatively, you can simply rename /usr/bin/python to /usr/bin/python2.3 and create a symlink pointing to the new version, e.g.
ln -s /usr/local/bin/python /usr/bin/python

- 1,826
- 10
- 13
-
-
1This only complicates matters if you need to change PYTHONPATH and possiby many other variables and settings as well. – tripleee May 21 '15 at 09:11
You can use checkinstall to remove Python, :
- Install checkinstall
- Use checkinstall to make a deb of your Python installation
- Use dpkg -r to remove the deb.
See this post for more details.

- 1
- 1

- 72
- 5