I would try cleaning it up manually. I've never done this so make sure you backup beforehand.

  • Remove the link from /etc/alternatives
  • Remove the relevant file from the admin directory
    • /var/lib/dpkg/alternatives/ on ubuntu (debian may be the same but check the man pages under the FILES section)
    • /var/lib/alternatives/ on CentOS 6&7
Answer from user9517 on serverfault.com
Top answer
1 of 2
9

I would try cleaning it up manually. I've never done this so make sure you backup beforehand.

  • Remove the link from /etc/alternatives
  • Remove the relevant file from the admin directory
    • /var/lib/dpkg/alternatives/ on ubuntu (debian may be the same but check the man pages under the FILES section)
    • /var/lib/alternatives/ on CentOS 6&7
2 of 2
11

Removing them manually resulted in ... is already managed by ... error in my case. Aside from that, the manual removal also didn't scale, as i've had added multiple multiple alternatives for the centralized symlink. It's just a mess.
When it comes to either update-alternatives or alternatives, they both provide the --remove and --remove-all flags. As for the former flag, it only removes one single alternative of the link group. For example

$ update-alternatives --list python3
/usr/bin/python3.8
/usr/bin/python3.9

$ sudo update-alternatives --remove python3 /usr/bin/python3.9

$ update-alternatives --list python3
/usr/bin/python3.8

The form of the --remove flag goes by update-alternatives --remove symlink-generic-name /path/to/one/executable/alternative

However, if you want to outright erase the generic name with all of its associated alternatives all at once, then --remove-all is the way to go.

$ update-alternatives --list python3
/usr/bin/python3.8
/usr/bin/python3.9

$ sudo update-alternatives --remove-all python3

$ update-alternatives --list python3
update-alternatives: error: no alternatives for python3

$ update-alternatives --query python3
update-alternatives: error: no alternatives for python3
Top answer
1 of 7
61

replace

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/bin/python python \
/usr/bin/python3.5 3

with

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python2.7 2

[bash:~] $ sudo update-alternatives --install /usr/local/bin/python python \
/usr/bin/python3.5 3

e.g. installing into /usr/local/bin instead of /usr/bin.

and ensure the /usr/local/bin is before /usr/bin in PATH.

i.e.

[bash:~] $ echo $PATH
/usr/local/bin:/usr/bin:/bin

Ensure this always is the case by adding

export PATH=/usr/local/bin:$PATH

to the end of your ~/.bashrc file. Prefixing the PATH environment variable with custom bin folder such as /usr/local/bin or /opt/<some install>/bin is generally recommended to ensure that customizations are found before the default system ones.

2 of 7
47

Per Debian policy, python refers to Python 2 and python3 refers to Python 3. Don't try to change this system-wide or you are in for the sort of trouble you already discovered.

Virtual environments allow you to run an isolated Python installation with whatever version of Python and whatever libraries you need without messing with the system Python install.

With recent Python 3, venv is part of the standard library; with older versions, you might need to install python3-venv or a similar package.

$HOME~$ python --version
Python 2.7.11

$HOME~$ python3 -m venv myenv
... stuff happens ...

$HOME~$ . ./myenv/bin/activate

(myenv) $HOME~$ type python   # "type" is preferred over which; see POSIX
python is /home/you/myenv/bin/python

(myenv) $HOME~$ python --version
Python 3.5.1

A common practice is to have a separate environment for each project you work on, anyway; but if you want this to look like it's effectively system-wide for your own login, you could add the activation stanza to your .profile or similar.

🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - Next, remove the broken alternative using the –remove option, and then reinstall the alternative with the correct path using the –install option. Solution: As the update-alternatives command modifies system-wide settings, you may encounter permission-related issues.
People also ask

Will installing multiple Python versions break system tools?
No, if done correctly. Rocky Linux 8 relies on /usr/bin/python3 for system tools. Avoid replacing it; instead, use alternatives or pyenv for custom projects.
🌐
centlinux.com
centlinux.com › home › rocky linux › install multiple versions of python on rocky linux 8
Install Multiple Versions of Python on Rocky Linux 8 | CentLinux
Why would I need multiple Python versions on Rocky Linux 8?
Different projects may require specific Python versions due to compatibility or dependency issues. Rocky Linux 8 ships with Python 3.6 by default, but you might need newer versions (e.g., 3.9 or 3.11) for modern frameworks like Django or Flask.

Solution: Use dnf for official RPM packages or pyenv for fine-grained version control.
🌐
centlinux.com
centlinux.com › home › rocky linux › install multiple versions of python on rocky linux 8
Install Multiple Versions of Python on Rocky Linux 8 | CentLinux
What’s the safest way to install additional Python versions without conflicts?
Following are the recommended methods for installing additional python versions without conflicts.

Official RPMs (Best for stability):

sudo dnf module install python39 # For Python 3.9

pyenv (Best for flexibility):

https://pyenv.run | bash # Installs pyenv
pyenv install 3.11.4 # Downloads and compiles Python 3.11.4

Manual compilation (Advanced users):

Download source from python.org and install to /usr/local/.

Avoid replacing /usr/bin/python3—system tools depend on it!
🌐
centlinux.com
centlinux.com › home › rocky linux › install multiple versions of python on rocky linux 8
Install Multiple Versions of Python on Rocky Linux 8 | CentLinux
🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
You can also remove all the available alternatives from the python alternatives with the following command: ... As you can see, there are no alternatives for python any more. ... So, that’s how you use update-alternatives command on Ubuntu to switch between different versions of the same program or command very easily.
🌐
GitHub
gist.github.com › 6910dd256f989abb41af30a8eeb01237
Update alternatives syntax for changing from python2.7 to python3.7 · GitHub
If you are on python2.7, we already know there will be no further development on that platform other than patches or security updates, so the only time you would need to modify will be for python3 revisions, etc. ... update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python).
🌐
LinuxConfig
linuxconfig.org › home › how to change from default to alternative python version on debian linux
How to change from default to alternative Python version on Debian Linux
December 7, 2023 - For example let’s remove python2.7 version: # update-alternatives --remove python /usr/bin/python2.7 update-alternatives: removing manually selected alternative - switching python to auto mode update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
Find elsewhere
🌐
CentLinux
centlinux.com › home › rocky linux › install multiple versions of python on rocky linux 8
Install Multiple Versions of Python on Rocky Linux 8 | CentLinux
February 27, 2026 - By leveraging the alternatives command, you can easily configure your desired Python version without the risk of overwriting or conflicting with other versions. This approach ensures flexibility, especially when working on diverse projects that rely on different Python versions or dependencies. To configure your preferred Python version, execute the following command, which updates the alternatives system to point to the desired Python binary.
🌐
GitHub
gist.github.com › patrickmmartin › 5b6b2ddecd29d6a1b2ffee2d8eea31ec
update-alternatives for python3 on Ubuntu · GitHub
ls -larth `which python`* -rwxr-xr-x 2 root root 4.3M Nov 17 19:23 /usr/bin/python3.5 -rwxr-xr-x 1 root root 3.4M Nov 19 09:35 /usr/bin/python2.7 lrwxrwxrwx 1 root root 24 Feb 5 09:36 /usr/bin/python -> /etc/alternatives/python ... sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2 $ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python).
🌐
Ask Ubuntu
askubuntu.com › questions › 1099776 › question-about-python-mapping-etc-alternatives-python
16.04 - Question about Python mapping (/etc/alternatives/python) - Ask Ubuntu
I have seen people use the following command to change the mapping for "python": sudo update-alternatives --config python # My output in this case: [sudo] password for m93: There are 3 choices for the alternative python (providing /usr/bin/python).
🌐
EdwardsLab
edwards.flinders.edu.au › no-python-in-centos-8
No python in CentOS 8 | EdwardsLab
January 23, 2020 - I don’t recommend doing this, because it sets a default python for everyone and negates exactly what the developers were trying to accomplish by eliminating the python command as detailed in the above blog post. However, a system-wide solution is to update-alternatives via either of these two commands:
🌐
Baeldung
baeldung.com › home › administration › setting the default python to python3
Setting the Default python to python3 | Baeldung on Linux
May 7, 2025 - Once more, let’s check if the Python version has changed to that contained in the path we chose: ... $ sudo update-alternatives --config python There is only one alternative in link group python (providing /usr/bin/python): /usr/bin/python3 Nothing to configure.
🌐
Brentknigge
brentknigge.com › notes › linux › linux-update-alternatives
Update Alternatives
You are presented with a menu to change the application you wish to have associated with python. In this case I will enter 1 so that python2 is now my default interpreter. ... Removing an entry is done with the following syntax. sudo update-alternatives --remove my_name application_path
🌐
Quora
quora.com › How-do-I-change-from-default-to-an-alternative-Python-version-on-Linux
How to change from default to an alternative Python version on Linux - Quora
Answer (1 of 5): When you develop with python, you really should consider environments, virtualenv or anaconda to name two. This allows you to install packages of different versions without filling your computer with packages that can conflict with some different packages. You can also lock down...
🌐
Baeldung
baeldung.com › home › administration › the update-alternatives command in linux
The update-alternatives Command in Linux | Baeldung on Linux
July 24, 2024 - On the other hand, removing the automatic choice alternative leads to selecting a new one with the highest priority. Finally, let’s list all alternatives available in the system with the get-selections command: $ update-alternatives --get-selections animate auto /usr/bin/animate-im6.q16 animate-im6 auto /usr/bin/animate-im6.q16 arptables auto /usr/sbin/arptables-nft awk auto /usr/bin/gawk builtins.7.gz auto /usr/share/man/man7/bash-builtins.7.gz c++ auto /usr/bin/g++ # ...