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.

🌐
GitHub
gist.github.com › joesan › c947ac9c9c3b851f818b29fe20084fdf
update-alternatives for python3 on Ubuntu · GitHub
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).
Discussions

python - Change the Python3 default version in Ubuntu - Unix & Linux Stack Exchange
I want to use python 3.6 with python3. ... I am installing ansible which supports version > 3.5 . So, whenever, I type ansible in the terminal, it throws error because of python 3.4 · sudo update-alternatives --config python3 update-alternatives: error: no alternatives for python3 More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 13, 2017
Switching between Python versions in Linux
Check what Python version are already ... desired and Y is the main one: sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.X 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3....... More on community.hailo.ai
🌐 community.hailo.ai
0
0
April 9, 2024
rhel - On RHEL8 how can I use `alternatives` to choose an already listed version as the used version - Unix & Linux Stack Exchange
On a RHEL 8.3 system I have two python3 versions installed and they show up as the version when I list alterantives' versions: $ alternatives --display python3 /usr/bin/python3.6 - priority 1000000 More on unix.stackexchange.com
🌐 unix.stackexchange.com
December 2, 2021
Use update-alternatives to manage additional Python versions
update-alternatives --install /usr/local/bin/python3 python3 /usr/local/python/3.12.7/bin/python3 1000 \ --slave /usr/local/bin/pip3 pip3 /usr/local/python/3.12.7/bin/pip3 More on github.com
🌐 github.com
1
November 4, 2024
🌐
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 - # update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode # update-alternatives --install /usr/bin/python python /usr/bin/python3.4 2 update-alternatives: using /usr/bin/python3.4 to provide /usr/bin/python (python) in auto mode
🌐
Baeldung
baeldung.com › home › administration › setting the default python to python3
Setting the Default python to python3 | Baeldung on Linux
May 7, 2025 - $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 update-alternatives: --install needs <link> <name> <path> <priority> Use 'update-alternatives --help' for program usage information.
Find elsewhere
🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
As you can see, the Python 2 interpreter path is /usr/bin/python2 and Python 3 interpreter path is /usr/bin/python3. Memorize them. We will need this later. Now, you can create a new alternatives python and install Python 2 interpreter /usr/bin/python2 as an alternative with the priority 20 as follows: $ sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python2 20
🌐
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
This can be frustrating if you want python to consistently point to Python 3. However, directly symlinking python to python3 (e.g., sudo ln -s /usr/bin/python3 /usr/bin/python) can break system tools like apt, which historically依赖 on Python 2 for legacy scripts. The safe solution is to use update-alternatives—a built-in Linux tool that manages system-wide command defaults without breaking dependencies.
🌐
GitHub
gist.github.com › GrowtopiaJaw › 7c5b7556c9b9a48aa68fe063107e1a5d
update-alternatives for python2 and python3 in Ubuntu 16.04.x · GitHub
We have 2 options available, python2.7 and python3.5 (These are default pythons that came with Ubuntu) ... 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).
🌐
Hailo Community
community.hailo.ai › general discussion
Switching between Python versions in Linux - General Discussion - Hailo Community
April 9, 2024 - Check what Python version are already ... desired and Y is the main one: sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.X 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.......
🌐
Brentknigge
brentknigge.com › notes › linux › linux-update-alternatives
Update Alternatives
At the moment I have python3 as the default intepreter, however I can easily change that with the following steps. ... 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
🌐
SciVision
scivision.dev › set-python-version-update-alternatives
Set Python version with update-alternatives | Scientific Computing
May 30, 2022 - How to use update-alternatives to persistently switch default system Python version.
🌐
DEV Community
dev.to › alfchee › how-to-switch-between-python-3-versions-5gh6
How to switch between Python 3 versions - DEV Community
September 2, 2020 - To check or configure the alternative of Python to use we need to run the command sudo update-alternatives --config python3, and the result will be similar to
🌐
SUSE
documentation.suse.com › 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 - Creating a custom python3 alternative pointing to a different version—such as python 3.11—breaks dependent system tools.
🌐
Claudia Kuenzler
claudiokuenzler.com › blog › 1301 › using-update-alternatives-avoid-python-bad-interpreter-point-to-python3
Using update-alternatives to avoid /usr/bin/python: bad interpreter and point python to python3
March 16, 2023 - root@linux:~# update-alternatives --install /usr/bin/python python /usr/bin/python3 1 update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode
🌐
GitHub
github.com › devcontainers › features › issues › 1172
Use update-alternatives to manage additional Python versions · Issue #1172 · devcontainers/features
November 4, 2024 - update-alternatives --install /usr/local/bin/python3 python3 /usr/local/python/3.12.7/bin/python3 1000 \ --slave /usr/local/bin/pip3 pip3 /usr/local/python/3.12.7/bin/pip3
Author   devcontainers
🌐
Seiden Group
seidengroup.com › home › how update-alternatives manages multiple versions of python, node.js, and other open source packages
How Update-Alternatives Manages Multiple Versions of Python, Node.js, and other Open Source Packages - Seiden Group
March 14, 2023 - To see all available versions of a specific package, or to change the defaults, run update-alternatives--config with the package name you’re interested in. The following example retrieves all versions of python: Note the values for Priority; in automatic mode, the package having the highest priority when enrolled becomes the preferred alternative automatically. In the example above, the highest priority is 309, making python3.9 the default version.