At the time of writing we can see when looking at dev-guide.python that the oldest supported version in Python 3.9 (until Nov 2025). However Ubuntu 20.x only ships with Python 3.8.
According to this stack overflow comment the easiest way to update python is as follows:
You can install python 3.9.5 in Ubuntu 20.04 even without the deadsnake PPA with the commands
sudo add-apt-repository universe
sudo apt update
sudo apt install python3.9
So lets go though these steps:
- The first line adds the universe repository, if it is not already available to the list of repositories available to the package manager apt. The Universe repository contains "software that is developed by the community, and may not be officially checked by Ubuntu". This includes Python 3.9.
- The second line updates the local list to match the most recent lists on the repository including version and dependencies etc.
- The command apt-get is finally used to the latest community version of Python, 3.9 of Ubuntu 20.x.
Summary
Thats it. You can run this version of Ubuntu in your scripts by prepending the version. You now have both 3.8 and 3.9 available. Apparently it is recommended to not change the default version of Python 3 from say 3.8 to 3.9 as this can cause some issues.
The default software in Ubuntu heavily rely on the default python version, and the default python version in Ubuntu is not meant to be changed.
I do want to update to a later version of Python but this will do for now. I just need to specify the version of Python to run with my scripts that require 3.9 or later.
TBH, I am not sure if it is best to update Ubuntu version and use the version. e.g. Ubuntu 22.x support python 3.10 out of the box. Alternatively I could look at running the deadsnakes compiled version, that it looks like I will need any way to run a later version even on 22.x or later.
Add new comment