Installing Python 3.12 on Ubuntu 25.04

As of July 2025, Python 3.12 is the latest stable and recommended version for production use. This guide walks you through installing it from source on Ubuntu 25.04.

Step-by-Step Installation Instructions

Update the System

apt update && sudo apt upgrade -y

Install Required Dependencies

apt install -y software-properties-common build-essential \
zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev \
libreadline-dev libffi-dev curl libsqlite3-dev wget llvm \
libbz2-dev tk-dev

@ Download Python 3.12 Source Code

cd /usr/src
wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgz
tar -xf Python-3.12.4.tgz
cd Python-3.12.4

Compile and Install Python

./configure --enable-optimizations
make -j$(nproc)
make altinstall

⚠️ Use make altinstall instead of make install to avoid overwriting the system's default python3.

Verify the Installation

python3.12 --version

Output:

Python 3.12.4

CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS