Python 3.12 is the default Python version on Ubuntu 24.04 LTS. It introduces improved error messages, a new type annotation syntax, and performance enhancements. This guide confirms the installation and shows how to set up Python development tools.
Tested and valid on:
- Ubuntu 24.04 LTS
Prerequisites
- Ubuntu 24.04 LTS server
- A user with sudo privileges
Step 1 – Check the Default Python Version
Ubuntu 24.04 ships with Python 3.12:
python3 --version
If Python 3.12 is not the default, install it from the Deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.12 -y
Step 2 – Install pip and Development Tools
Install pip and essential development packages:
sudo apt install python3-pip python3.12-dev python3.12-venv build-essential -y
Step 3 – Verify pip Installation
Confirm pip is available:
pip3 --version
Step 4 – Set Python 3.12 as Default (optional)
If multiple Python versions are installed:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1
sudo update-alternatives --config python3
Step 5 – Create a Virtual Environment
Always use a virtual environment for projects:
python3.12 -m venv ~/myproject/venv
source ~/myproject/venv/bin/activate
Step 6 – Install Packages in the Virtual Environment
Install packages without affecting the system Python:
pip install requests flask django
Step 7 – Deactivate and Manage the Environment
Deactivate when done:
deactivate
Reactivate later:
source ~/myproject/venv/bin/activate
Conclusion
Python 3.12 is ready to use on Ubuntu 24.04 LTS. Always use virtual environments to isolate project dependencies and avoid conflicts with system packages.