Upgrade Python to latest version on Ubuntu Linux

  1. First, update your system by running
1
sudo apt update && sudo apt upgrade -y
1
2
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
  1. Check if Python 3.12 is available by running
1
apt list | grep python3.12
  1. Install Python 3.12
1
sudo apt install python3.12
  1. Run Python 3.12
1
python3.12 --version

The right way to run Python 3.12 On Linux Desktops is by using a virtual environment.
E.g. you can create a new virtual environment by running

1
python3.12 -m venv env

and activate it by running

1
source env/bin/activate

Now you can run python --version and you should see the latest version of Python as the output.

參考資料: