Skip to main content
If you have multiple Python versions installed on your Ubuntu system, you can configure which one is used by default.

Set the Default Python Version

1
Find installed Python versions
2
First, check the installed Python versions on your system and copy the path to the version you want to set as default.
3
# copy the path to your python version
whereis python3.13 # replace your version with the one you want to set as default
4
Register the version with update-alternatives
5
Use the update-alternatives command to register your Python version. The higher the priority value, the higher the priority of that version.
6
sudo update-alternatives --install /usr/bin/python3 python3 <replace-your-path> <priority-value>
# example
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.13 1
sudo update-alternatives --config python3 # select the version you want to set as default
7
You will see output similar to this — enter the selection number for the version you want:
8
There are 2 choices for the alternative python3 (providing /usr/bin/python3).

  Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /usr/local/bin/python3.12   2         auto mode
  1            /usr/bin/python3.13         1         manual mode
  2            /usr/local/bin/python3.12   2         manual mode

Press <enter> to keep the current choice[*], or type selection number: 1
9
Verify the default version
10
python3 --version
11
(Optional) Set default for the python command
12
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.13 1
sudo update-alternatives --config python
python --version

Build docs developers (and LLMs) love