How to Compile and Install Python 3.10 or 3.11 in Debian 11 bullseye

This tutorial shows how to install and setup the Python programming language 3.10 in Debian 11 bullseye.

Python 3.10 is the latest LTS version of the interpreted high-level general-purpose programming language released a few days ago. It features pattern matching, writing union types as X | Y, OpenSSL 1.1.1, and more. And it has 18-month support with bug-fix updates, and 5-year support with security updates.

Unlike Fedora and Ubuntu, there’s neither official package nor PPA repository that contains Python 3.10 package for Debian users. However, compiling Python from source is easy and here’s how!

UPDATE: This tutorial is also tested and works with Python 3.11. Though, you have to change the version number in the following commands.

Build Python 3.10 in Debian 11:

Firstly, open terminal from start menu or connect to Debian Server command console. Next run following commands one by one to build Python 3.10 either in Debian 11 Desktop and/or Server.

1. Install Dependencies:

In terminal or command console, first update system package by running command:

sudo apt update

Next install essential packages for downloading the source and building the program:

sudo apt install wget build-essential libreadline-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev

2. Download Python 3.10 / 3.11:

Then download the source tarball either by running the wget command:

wget -c

NOTE: Python 3.10 is keep updating with point releases! At the moment of writing, the latest is 3.10.11. But newer versions may be out when you see this tutorial! So, go check this download page and replace 3.10.11 in command with the latest or your desired version number!

For Python 3.11, use the command below instead to download the tarball (also replace point version number accordingly).

wget -c

After that, extract the source tarball either via file manager or using command (change release number 3.10.11 accordingly):

tar -Jxvf Python-3.10.11.tar.xz

3. Build Python 3.10:

After downloading and extracting the source tarball, navigate to the generated source folder via cd command (also replace 3.10.11 to yours version number):

cd Python-3.10.11

And configure with expensive, stable optimizations (PGO, etc.):

./configure --enable-optimizations

Finally, build and install Python 3.10 into /usr/local/bin directory without overriding the system built-in Python installation:

sudo make -j4 && sudo make altinstall

Depends on your CPU, change -j4 (4 threads) in command to tell start how many threads for the building process.

4. Verify Python 3.10 installation:

After installation, verify it via command:

python3.10 --version
pip3.10 --version

For Python 3.11, run python3.11 --version and pip3.11 --version instead.

Set Python 3.10 as default in Debian 11:

Debian 11 by default uses python 3.9 as default for python3 executable and leave ‘python’ un-configured. Users may link Python3.10 to python easily via update-alternatives command:

1.) Set Python3.10 as python via command:

sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1

2.) For pip, it’s recommended to use python3.10 -m pip install command. If you insists, run command below to set it as default.

sudo update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.10 1

After that, run python --version and pip --version to check results.


As you see, it’s quite easy to compile Python 3.10/3.11 from source tarball. Just install dependencies, download source and build it. And it installs in a few minutes in my case with no error occurred. As well, users may set Python 3.10 and Pip 3.10 as default easily by creating symbolic links using update-alternatives command.

Hi, I'm Merilyn Ne, a computer geek working on Ubuntu Linux for many years and would like to write useful tips for beginners. Forgive me for language mistakes. I'm not a native speaker of English.
%d bloggers like this: