Update python
Method 1: using deadsnakes ppa (Recommended)
On Ubuntu, the cleanest way is usually the deadsnakes PPA.
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12 python3.12-venv python3.12-dev
Check version
python3.12 --version
You should see something like: Python 3.12.x
Update default python (Not Recommended)
Changing Ubuntu’s system python3 default is risky because apt, desktop tools, and OS scripts may expect the Ubuntu-provided Python. The safer system-wide-ish method is update-alternatives, which is reversible.
First check paths:
which python3.10
which python3.12
Then register both versions:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 10
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 20
Select Python 3.12:
sudo update-alternatives --config python3
Verify:
python3 --version
To switch back later:
sudo update-alternatives --config python3
NOTE: if Ubuntu tools start failing, switch back to the distro default immediately. On many Ubuntu versions, changing /usr/bin/python3 is not recommended; aliases or virtual environments are safer.
©2023-2024 rculock.com