Post

Installing Python 3.12 on Debian 12 A Step-by-Step Guide

As a developer, staying up-to-date with the latest versions of programming languages is crucial for leveraging new features and optimisations. In this article, we’ll walk through the process of installing Python 3.12 on Debian 12.

Why Install Python 3.12?

Python 3.12 is the newest major release of the Python programming language, boasting numerous improvements and enhancements. By installing this version, you can take advantage of these updates and improve your development workflow.

Manual Installation from Source Code

While it’s possible to install Python from a repository, we’ll explore the manual installation process using source code. This method provides more control over the installation process and allows for customization.

Update System

Before proceeding, ensure your system is up-to-date by running:

1
apt update -y

Next, upgrade any existing packages to their latest versions:

1
apt upgrade -y

Install Required Dependencies

Install necessary packages to build Python from source:

1
2
3
apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git

Download Python Source Code

Visit the Python downloads page to retrieve the source code. Then, using wget, download the source:

1
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

Extract and Configure the Archive

Extract the downloaded archive:

1
tar -xf Python-3.12.0.tgz

Navigate to the extracted directory:

1
cd Python-3.12.0

Configure and build Python with optimizations enabled:

1
./configure --enable-optimizations

Build and Install Python

Build Python using multiple CPU cores (replace 8 with your desired number of cores):

1
make -j 8

Finally, install Python without replacing the system’s default interpreter (using altinstall):

1
make altinstall

Verify Installation

Check if Python 3.12 has been installed successfully:

1
python3.12 --version

The output should display the version you just installed:

1
2
3
root@vps:~/Python-3.12.0# python3.12 --version
Python 3.12.0
root@vps:~/Python-3.12.0#

By following these steps, you’ve successfully installed Python 3.12 on your Debian 12 system. Enjoy the benefits of this new version and explore its features!

This post is licensed under CC BY 4.0 by the author.