How to install Python 3.12.2 on Debian 11 bullseye

Published March 02, 2024

How to install Python 3.12.2 on Debian 11

The latest version of Python is 3.12.2 and is the second maintenance release, with more than 350 bugfixes since 3.12.1.

I use Debian 11 for a lot of my work , and would like to have the latest Python 3.12.2. Unfortunately, Debian 11 stable includes a much older version. This tutorial will help you install Python 3.12.2 on Debian 11 by building it from source.


I use Linode for my web hosting. It is an awesome hosting company. I use the unmanaged plan, so that means I get to install Nginx, configure the system and install the latest and greatest version of Python, which is 3.12.2.

Go get your Linode account with $100 free credits for 60 days.

Install Python using apt

The default version of Python on Debian 11 is Python 3.9.2. If you are happy with it, good.

$ apt info python3
Package: python3
Version: 3.9.2-3
Priority: optional
Section: python
Source: python3-defaults
Maintainer: Matthias Klose <>
Installed-Size: 91.1 kB
Provides: python3-profiler
Pre-Depends: python3-minimal (= 3.9.2-3)
Depends: python3.9 (>= 3.9.2-0~), libpython3-stdlib (= 3.9.2-3)
Suggests: python3-doc (>= 3.9.2-3), python3-tk (>= 3.9.2-0~), python3-venv (>= 3.9.2-3)
Replaces: python3-minimal (<< 3.1.2-2)
Tag: devel::interpreter, devel::lang:python, devel::library,
 implemented-in::c, implemented-in::python, role::devel-lib,
 role::program, role::shared-lib
Cnf-Extra-Commands: python
Cnf-Priority-Bonus: 5
Download-Size: 37.9 kB
APT-Manual-Installed: no
APT-Sources: bullseye/main amd64 Packages
Description: interactive high-level object-oriented language (default python3 version)
 Python, the high-level, interactive object oriented language,
 includes an extensive class library with lots of goodies for
 network programming, system administration, sounds and graphics.
 This package is a dependency package, which depends on Debian's default
 Python 3 version (currently v3.9).

If you want to upgrade to 3.12.2, read on.

Previous versions of Python

If you are using any previous version of Python, such as 3.12.1 or 3.11, this article is applicable.

Download Python 3.12.2 source

Python 3.12.2 was released on February 6, 2024. The latest Python source code is available here.

Download and extract the Python source code.

cd /tmp/
tar -xzvf Python-3.12.2.tgz
cd Python-3.12.2/


$ cd /tmp/
$ wget
--2024-02-08 12:48:45--
Resolving (, 2a04:4e42:77::223
Connecting to (||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 27116462 (26M) [application/octet-stream]
Saving to: โ€˜Python-3.12.2.tgzโ€™

Python-3.12.2.tgz          100%[=====================================>]  25.86M  2.15MB/s    in 12s     

2024-02-08 12:48:57 (2.20 MB/s) - โ€˜Python-3.12.2.tgzโ€™ saved [27116462/27116462]


Install the build tools

Now, install the build tools. The build tools includes gcc, make, zlib, ssl libraries and other libraries.

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev

If you are prompted to install other dependencies, select yes.

Configure, make and make install

Run the configure script and enable Profile guided optimization (PGO) and Link Time Optimization (LTO). This can boost up speed up to 20%.

./configure --enable-optimizations

Now run make. You can make the build using nproc, which returns the number of CPUs.

make -j `nproc`

This step can take several minutes.

Make install

The default Python installation is /usr/bin. If you want to install Python under /usr/local/bin instead of overwriting the default, do this:

sudo make altinstall

This will install Python at /usr/local/bin/python3.12. To test the version, run this:

python3.12 -V

You will get this output:

Python 3.12.2

Make Python 3.12.2 the default version

To make the default version of Python 3.12.2, run this:

sudo ln -s /usr/local/bin/python3.12 /usr/local/bin/python

This creates a bunch of softlinks and links the latest Python to /usr/local/bin.

ln: failed to create symbolic link '/usr/local/bin/python': File exists

If you get this error:

ln: failed to create symbolic link '/usr/local/bin/python': File exists

that means that you already have a softlink at that location. Delete the softlink.

$ sudo rm /usr/local/bin/python

Then, repeat the softlink create command:

$ sudo ln -s /usr/local/bin/python3.12 /usr/local/bin/python

Now, verify it:

$ ls -al /usr/local/bin/python
lrwxrwxrwx 1 root root 25 Dec 26 13:08 /usr/local/bin/python -> /usr/local/bin/python3.12

Test if Python 3.12.2 is the default version

Test whether Python 3.12.2 is the default version:

$ ls -al /usr/local/bin/python
lrwxrwxrwx 1 root root 25 Dec 26 13:08 /usr/local/bin/python -> /usr/local/bin/python3.12

$ ls -al /usr/local/bin/python3.12
-rwxr-xr-x 1 root root 37195824 Feb  8 18:00 /usr/local/bin/python3.12

$ /usr/local/bin/python3.12 -V
Python 3.12.2
python -VV

The output will be:

Python 3.12.2 (main, Feb  8 2024, 13:06:49) [GCC 10.2.1 20210110]

So, at this point, Python 3.12.2 has been set as the default version of Python.

Hope this worked for you. If you have any issues installing Python on your Debian 11 system, feel free to comment below or email me.

Related Posts

If you have any questions, please contact me at arulbOsutkNiqlzziyties@gNqmaizl.bkcom. You can also post questions in our Facebook group. Thank you.

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Last Updated: March 02, 2024. ย ย ย  This post was originally written on January 26, 2023.