First we have to add repository source code so open terminal and run following command:
sudo add-apt-repository ppa:deadsnakes/ppa
Next update the apt library:
sudo apt update
Finally, install python3.12 in your Linux system:
sudo apt install python3.12