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.

Answer from jonrobm on Stack Overflow
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.

🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
As you can see, the /usr/bin/python2 (Python 2 interpreter) alternative is removed from the python alternatives.
Discussions

How to set default Python version without --update-alternatives - Stack Overflow
I have Python3.6 and Python3.8 installed on Ubuntu 18.04. When I execute python3 -V I get python3.8.0, which is correct. That's currently my default Python. I used the Ubuntu 18.04 package reposi... More on stackoverflow.com
🌐 stackoverflow.com
debian - How to prevent changing default Python version? - Unix & Linux Stack Exchange
Many applications I use (arandr, inkscape, ...) get broken when default Python version is set to Python-3 by update-alternatives --config python. How can I prevent myself from setting default Python More on unix.stackexchange.com
🌐 unix.stackexchange.com
Remove python2, set python3 as default /usr/bin/python
I'm not sure removing python2 is a good idea.Some system programs could need it. I'd rather have made a python simlink pointing to py3 More on reddit.com
🌐 r/openSUSE
15
10
December 13, 2020
How to change Python and Pip version in Ubuntu
You shouldn’t tamper with the system installation of python and there really isn’t a way to “change the defaults” globally. You should look into virtual environments: https://docs.python.org/3/library/venv.html In short, create a virtual environment based on the global 3.9 installation and once activated it would point python to python3.9 for you until you deactivate it. More on reddit.com
🌐 r/bashonubuntuonwindows
9
14
January 17, 2021
🌐
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
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
🌐
TecAdmin
tecadmin.net › linux-update-alternatives-command
Update-alternatives Command: A Comprehensive Guide for Linux Users – TecAdmin
April 26, 2025 - sudo update-alternatives --remove python /usr/bin/python3.8 · Example: sudo update-alternatives --config python · Example: sudo update-alternatives --auto python · Example: update-alternatives --display python · For example, you have 2 versions of Java installed on your system.
Find elsewhere
🌐
pythontutorials
pythontutorials.net › blog › how-to-update-alternatives-to-python-3-without-breaking-apt
How to Set Python 3 as Default with update-alternatives (Without Breaking apt) — pythontutorials.net
If apt errors persist, remove the python alternative: sudo update-alternatives --remove python /usr/bin/python3.10 # Replace with your Python 3 path
Top answer
1 of 1
6

Python 2.X packages are named differently than Python 3.X packages in the default Ubuntu repositories, python-... for Python 2.X packages vs. python3-... for Python 3.X packages. The command to start the Python interpreter follows a similar pattern, python for the default Python 2.X version vs. python3 for the default Python 3.X version.

Don't remove the default Python 3.x version because removing it can break a lot of things like the terminal, the Software app and many other apps. For more information see this question: Removed Python 3 and now Ubuntu Software Center, terminal and other applications don't work. The good news is that even if you break those things it is possible to restore the original Python 3.x version by booting Ubuntu into recovery mode, and then Ubuntu will work normally again.

Instead of replacing the default Python 3.x version entirely the recommended way of installing another Python 3.x version is to keep the existing Python 3 and install the new Python 3 version alongside it. Then you can use a program called update-alternatives to select which one of the Python versions you want to use.

Add Python 3.8 to update-alternatives so that you can switch between Python 3.5 and Python 3.8 by running update-alternatives --config python3.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8
update-alternatives --config python3

After you are done using Python 3.8 you can switch the it back to the default Python 3.5 version.

  • List installed versions of Python: update-alternatives --list python

  • Switch between Python versions: update-alternatives --config python

    From the terminal command-line Press <enter> to keep the current choice[*], or type selection number:

🌐
GitHub
gist.github.com › patrickmmartin › 5b6b2ddecd29d6a1b2ffee2d8eea31ec
update-alternatives for python3 on Ubuntu · GitHub
python3 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 5 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
🌐
Python Forum
python-forum.io › thread-33298.html
Eliminating error in Python update-alternatives
I made an error when typing this code: sudo update-alternatives --install /usr/bin/python3 python /usr/bin/python2.7 1Obviously, I do not want to that. It create issues like this: Output:root@LAPTOP-8R8F1BRA:/home/james# python -V Python 2.7.17 ro...
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1779294 – Installing python from alternatives, removes default python symlink
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red ...
🌐
Lyons Computer
lyonscomputer.com.au › Linux › python-update-alternatives › python-update-alternatives.html
VK4PK - python update-alternatives
python update-alternatives · apt install python-is-python3 · lsb_release -a # OS version python --version # currently linked python vwersion which python which python2 which python3 # Add some alternatives sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python2 20 ...
🌐
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).
🌐
SUSE
documentation.suse.com › fr-fr › sles › 15-SP6 › html › SLES-all › cha-update-alternative.html
update-alternatives: managing multiple versions of commands and files | Administration Guide | SLES 15 SP6
March 30, 2026 - There is a master link foo that points to either foo-2 or foo-3. To provide alternatives on your system, follow these steps: Copy your scripts into the /usr/local/bin directory. ... > sudo update-alternatives ...
🌐
Baeldung
baeldung.com › home › administration › the update-alternatives command in linux
The update-alternatives Command in Linux | Baeldung on Linux
July 24, 2024 - Let’s notice that this happens thanks to the postinst script, which is triggered after the installation of the package. By the same token, the prerm and postrm scripts update alternatives during the removal of the package.