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.

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
ubuntu - sudo update-alternatives --config . How to set the auto entry - Unix & Linux Stack Exchange
I'm trying to run a script that does somewhere: python setup.py egg_info This gives me an error. But if I manually do : python3 setup.py egg_info I don't get the error. Therefore I tried to sudo update-alternatives --config python . More on unix.stackexchange.com
🌐 unix.stackexchange.com
June 27, 2022
Unable to upgrade Python 3.8.10 to 3.10 - SOLVED
We basically followed the following page for instructions: When we reached 2nd command in Step 3: Add Python 3.8 & Python 3.10 to update-alternatives, we see this error. $ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2 update-alternatives: error: alternative ... More on discuss.python.org
🌐 discuss.python.org
10
0
May 15, 2022
🌐
GitHub
gist.github.com › patrickmmartin › 5b6b2ddecd29d6a1b2ffee2d8eea31ec
update-alternatives for python3 on Ubuntu · GitHub
python2 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.4 5 · 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
🌐
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
🌐
KarChunT
karchunt.com › blog › setup-default-python-version-on-ubuntu
Setup Default Python Version on Ubuntu | KarChunT
# copy the path to your python version whereis python3.13 # replace your version with the one you want to set as default · Then, you can set the default Python version using the update-alternatives command.
🌐
Linux Hint
linuxhint.com › update_alternatives_ubuntu
How to Use update-alternatives Command on Ubuntu – Linux Hint
The same way, install Python 3 interpreter /usr/bin/python3 as an alternative of the python alternatives and set it a priority of 40 with the following command: $ sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3 40
🌐
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.......
Find elsewhere
🌐
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 - Then save and close the file. Next, update the default Python by adding both versions to an alternatives by running the below · sudo update-alternatives --install /usr/bin/python3 ...
🌐
Brentknigge
brentknigge.com › notes › linux › linux-update-alternatives
Update Alternatives
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
🌐
GitHub
gist.github.com › GrowtopiaJaw › 7c5b7556c9b9a48aa68fe063107e1a5d
update-alternatives for python2 and python3 in Ubuntu 16.04.x · GitHub
Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/python3.5 2 auto mode 1 /usr/bin/python2.7 1 manual mode 2 /usr/bin/python3.5 2 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 ... sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python2.7 2 sudo update-alternatives --config python3 There are 2 choices for the alternative python3 (providing /usr/bin/python3).
🌐
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/local/bin/python3.11 20 $ sudo update-alternatives --config python There are 2 choices for the alternative python (providing /usr/bin/python).
🌐
Medium
rem-baba.medium.com › python-version-switch-manager-f4e34b3c6d9e
Python version switch manager. The objective of this tutorial is to… | by Ramesh Babu Chayapathi | Medium
July 10, 2023 - Step 3 In this step we are going to set two Python alternatives, namely it will by Python2 and Python3 alternative. Execute the following commands: $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 $ sudo ...
🌐
Kali Linux
kalilinux.in › home › configure › set default version of python : [solved] update-alternatives: error: no alternatives for python3
Set Default Version of Python : [SOLVED] update-alternatives: error: no alternatives for python3 - Kali Linux Tutorials
July 31, 2025 - Here automatically 0 is chosen for Python 3.9 version, we can go for it, otherwise instead of choosing by numbers we can run following command to choose the default python3 version: sudo update-alternatives --set python3 /usr/bin/python3.9
🌐
Jonathan Cutrer
jcutrer.com › home › how to upgrade to python 3.7 on ubuntu 18.10
How to upgrade to python 3.7 on ubuntu 18.10 - jcutrer.com
June 10, 2019 - You can still install and use python 3.7 on Ubuntu Desktop machine just skip the update-alternatives steps below. To use 3.7 instead of 3.6 just execute python3.7 directly, create a virtualenv or use pipenv. Steps to install python3.7 and configure it as the default python3 interpreter. ... sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
🌐
Python.org
discuss.python.org › python help
Unable to upgrade Python 3.8.10 to 3.10 - SOLVED - Python Help - Discussions on Python.org
May 15, 2022 - We basically followed the following ... 3.10 to update-alternatives, we see this error. $ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2 update-alternatives: error: alternative .....
🌐
ITSupportWale
itsupportwale.com › home › how to upgrade to python 3.10 on ubuntu 18.04 and 20.04 lts
How to upgrade to Python 3.10 on Ubuntu 18.04 and 20.04 LTS - ITSupportWale
February 17, 2026 - Press to keep the current choice[*], or type selection number: 0 update-alternatives: using /usr/bin/python3.10 to provide /usr/bin/python3 (python3) in auto mode $ $ $ python3 -V Python 3.10.4 $ sudo update-alternatives –config python3 There ...