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
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).
🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
using update-alternatives command, you can make a new executable python (/usr/local/bin/python) and add all the available Python versions to the alternatives database. Then, you can easily set which version of Python to use by default. You can also switch between the Python versions very easily.
🌐
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 - In case we no longer have the alternative python version installed on our system we can remove its update-alternatives listing. 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
🌐
Brentknigge
brentknigge.com › notes › linux › linux-update-alternatives
Update Alternatives
First lets find out where our installations of python are located. ... Now we can add the executables. sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python2 20 sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3 30
🌐
CloudBytes
cloudbytes.dev › home › snippets › upgrade python to latest version (3.14) on ubuntu linux or wsl2
Upgrade Python to latest version (3.14) on Ubuntu Linux or WSL2 · CloudBytes/dev
April 13, 2026 - sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.14 2
Find elsewhere
🌐
Hackers and Slackers
hackersandslackers.com › multiple-python-versions-ubuntu-20-04
Managing Multiple Versions of Python on Ubuntu 20.04
February 25, 2021 - update-alternatives is a CLI interface for installing and switching between alternative versions of packages. This applies to programming languages (like python), text editors (like vim), and really anything else apt can install.
🌐
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 ...
🌐
Ask Ubuntu
askubuntu.com › questions › 1489964 › update-alternatives-is-it-generally-usable
python3 - update-alternatives, is it *generally* usable? - Ask Ubuntu
So, the general answer to the usability of update-alternatives is: No The packages has to cooperate regarding it. w.r.t. Python and PySide6; Found one option each... $ python -m pip install pyside6 ... installs nicely on a fully updated 20.04 at least. The newer python on the other hand... I haven't tried it out yet (need a full backup first), but then: The "deadsnakes ppa" seems to be a usable option - see https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa
🌐
LinuxTut
linuxtut.com › en › ee27a9c53dc57d90e7b3
Manage multiple Python versions with update-alternatives (Ubuntu)
May 11, 2020 - Of course, don't forget to revert to the original Python version at the end. kohei@kohei-VirtualBox:~$ sudo update-alternatives --config python There are 3 choices for the alternative python (providing /usr/bin/python).
🌐
Towards Data Science
towardsdatascience.com › installing-multiple-alternative-versions-of-python-on-ubuntu-20-04-237be5177474
Installing multiple alternative versions of Python on Ubuntu 20.04 | by Mathanraj Sharma | Towards Data Science
April 5, 2023 - If you are using Ubuntu 20.04 you will have python version 3.8 by default. Let’s install python 3.7, sudo apt-get install software-properties-common# adding python repository sudo add-apt-repository ppa:deadsnakes/ppasudo apt update# install python 3.7 sudo apt install python3.7
🌐
RoseHosting
rosehosting.com › home › how to install and switch python versions on ubuntu 20.04
How to Install and Switch Python Versions on Ubuntu 20.04 | RoseHosting
October 5, 2022 - We are going to create symlinks for the following Python versions respectively: Python2.7, Python3.5, Python3.6, Python3.7, and Python3.8 Next to the symlink we are going to add the group name python and the option number. ... 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 --install /usr/bin/python python /usr/bin/python3.6 3 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 4 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 5
🌐
TecAdmin
tecadmin.net › how-to-switch-python-version-in-ubuntu-debian
How to Change Default Python Version on Ubuntu & Debian
April 26, 2025 - Change the symbolic link to /usr/bin/python3.10 and keep the group name as “python”. The group name must be the same for all Python versions. sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2
🌐
OperaVPS
operavps.com › docs › how to change python default version in debian/ubuntu
How to Change Python Default Version in Debian/Ubuntu
February 12, 2026 - By using the update-alternatives command, you can prioritize the executable Python, and the version that has a high priority is set as the default version. By running the python -V command, the available version of Python will be displayed.
🌐
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 ... the alternatives where X is the desired and Y is the main one: sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.X 1 sudo update-alternatives --install ...