How to Install Python 3.9 on Debian 12, 11 or 10

Python 3.9 remains relevant for developers and system administrators working on Debian systems, including Debian 12 Bookworm, Debian 11 Bullseye, and Debian 10 Buster. This version offers a balance of stability and features, making it a viable option for various use cases.

Key Considerations for Python 3.9 on Debian 12, 11 or 10

  • Compatibility: Python 3.9 is often required for applications or libraries that haven’t yet adapted to newer Python versions.
  • Controlled Testing: Developers may use Python 3.9 in a controlled environment to test applications before upgrading to a newer Python version.
  • Educational Use: Certain educational settings may specify using Python 3.9 for instructional purposes.

While Python 3.10 and 3.11 offer advanced features and optimizations, Python 3.9 provides a stable alternative for those who need it. This guide aims to be your go-to resource for installing Python 3.9 on Debian systems, whether you’re using Debian 12 Bookworm, Debian 11 Bullseye, or Debian 10 Buster. Stay tuned for step-by-step installation instructions.

Section 1: Install Python 3.9 via source on Debian 12, 11 or 10

This section will install Python 3.9 on Debian by compiling it from the source code. This approach provides the utmost control over the installation process. It guarantees that you obtain the most recent release of Python 3.9, which is unavailable in the default archives of Debian 11 Bullseye and Debian 12 Bookworm.

Step 1: Update Debian System Packages Before Python 3.9 Installation

To begin, it’s essential to update the Debian system packages. This step is crucial as it ensures compatibility between the existing packages and the ones that will be installed.

sudo apt update && sudo apt upgrade

Step 2: Install Development Packages for Python 3.9 on Debian 12, 11, or 10

In this step, we will install a group of packages necessary for compiling Python from the source code. These packages include development libraries and utilities that will facilitate the compilation process.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev -y

Step 3: Download Python 3.9 Source Code on Debian 12, 11, or 10

Next, download the Python 3.9 source code from the official Python website. Make sure to download the latest version of Python 3.9, which at the time of this writing is Python 3.9.17.

It’s advisable to visit the official Python website to verify if there is a newer release version available. The link provided in this guide serves as an example; be sure to modify it accordingly to download the most recent version in the future.


Step 4: Extract Python Archive and Move to Appropriate Directory on Debian

After downloading the source code, extract it using the tar command.

tar -xf Python-3.9.17.tar.xz

For structure and organization, it is advisable to move the extracted files to a standard directory within /usr/local/. In this guide, we will place them in /usr/local/share.

mv Python-3.9.17 /usr/local/share/python3.9

Step 5: Configure, Compile, and Install Python 3.9 on Debian 12, 11 or 10

Now, change to the directory containing the Python source code. We will execute the ./configure script with specific flags for optimization and enabling shared libraries.

cd /usr/local/share/python3.9
./configure --enable-optimizations --enable-shared

The --enable-optimizations flag ensures that the script performs dependency checks and optimizes the Python binary by running tests. The --enable-shared flag is used to build shared libraries, which are essential for specific types of applications.

Consider using the --with-ensurepip=install flag to install the pip package manager alongside Python.

Now, compile the source code using the make command.


To expedite the compilation process on systems with multiple CPU cores, use the -j flag followed by the number of CPU cores to be utilized. For example, to use 5 CPU cores:

make -j 5

After the compilation is finished, install the Python binaries. It is recommended to use the make altinstall command to prevent overwriting the default Python binary in the system.

sudo make altinstall

After the installation, it is imperative to configure the dynamic linker run-time bindings. This step is vital and should not be overlooked as it can prevent potential issues.

sudo ldconfig /usr/local/share/python3.9

To ensure that Python 3.9 has been installed successfully, verify the installation by checking the Python version. This step is vital to confirm that Python 3.9 is properly installed and ready for use.

python3.9 --version

You should see output indicating the installed Python version, similar to:

Python 3.9.17

Section 2: Create a Virtual Environment with Python 3.9 on Debian

This segment focuses on establishing a virtual environment utilizing Python 3.9. Virtual environments are crucial in Python development for segregating project-specific dependencies, ensuring no clashes with other Python projects or system libraries.

Step 1: Create a Test Project Directory on Debian

Initiating the process, we need to construct a directory to store our Python project and establish the virtual environment therein. Use the following commands to forge a directory named test_app and navigate to it:

mkdir ~/test_app
cd ~/test_app

Step 2: Initiating a Virtual Environment

With our presence in the project directory, creating a virtual environment is time. We will capitalize on Python’s venv module, which has been integral to Python since version 3.3. The venv the module is adept at crafting streamlined virtual environments.

To spawn a virtual environment named test_app_venv, run the subsequent command:

python3.9 -m venv test_app_venv

Here, -m venv signifies the utilization of the venv module. test_app_venv is designated as the virtual environment’s name, though you can confer any name that aligns with your project.

Step 3: Engaging the Virtual Environment

Having created the virtual environment, we must now engage it. Activation confines the environment, ensuring that Python commands and installations remain exclusively within its boundaries.

Bring the virtual environment online by executing the following:

source test_app_venv/bin/activate

Confirmation of activation is apparent as the name of the virtual environment emerges at the start of the terminal prompt, for instance:

(test_app_venv) root@debian:~/test_app# 

This indicates the operational status within the test_app_venv virtual environment. Consequently, Python packages installed henceforth will be accessible solely within this environment.

Step 4: Disengaging the Virtual Environment

Upon the conclusion of tasks within the virtual environment, it is prudent to disengage it to revert to the system-wide Python environment. Accomplish this by inputting:


Post-deactivation, the terminal prompt’s prefix vanishes, confirming your exit from the virtual environment.

Section 3: Install Pip with Python 3.9 on Debian 12, 11, or 10

This section delineates installing Python’s package manager, Pip, along with Python 3.9. Pip is an indispensable asset for Python developers, as it streamlines the installation and management of Python libraries and packages.

Step 1: Validating the Installation of Pip on Debian 12, 11 or 10

Python 3.9 generally comes equipped with Pip. However, there are instances where Pip might not be installed or could be improperly installed. It’s prudent to validate if Pip is installed with Python 3.9. Execute the following command:

python3.9 -m pip --version

If Pip is installed, the version will be displayed. If not, manual installation is required, as outlined in the succeeding steps.

Step 2: Download the Pip Installation Script on Debian 12, 11 or 10

To incorporate Pip with Python 3.9, a Python script is needed to oversee the installation. This script, termed, is obtainable via the wget command.

Execute the command below to procure the Pip installation script:


This command fetches from the official repository and stores it in the current directory.

Step 3: Integrating Pip with Python 3.9

With the script in hand, we can proceed to install Pip. Execute the following command to run the script utilizing Python 3.9:


This instructs Python 3.9 to execute the script, culminating in the installation of Pip.

Step 4: Upgrading Pip to the Latest Version on Debian

Despite the fresh installation of Pip, it is advisable to ascertain that the latest version is in use. Pip undergoes active development, and recent versions often encompass critical fixes and enhancements.

Execute the following command to elevate Pip to its latest version:

python3.9 -m pip install --upgrade pip

This leverages the instance of Pip in Python 3.9 to upgrade itself to the most recent version.

Step 5: Confirming the Pip Installation on Debian 12, 11 or 10

After completing the installation and upgrade, confirming that Pip is functioning correctly is essential. Run the following command to check the version of Pip that is currently installed:

python3.9 -m pip --version

This should display the installed Pip version, which should be the latest version of the successful upgrade.


In this article, we navigated through the systematic process of installing Python 3.9 on a Debian Linux system. We started by updating the package list and downloading and installing Python 3.9 from the official source. Next, we explained the importance of setting up a virtual environment, which enables the isolation of project dependencies, thus preventing conflicts with system libraries. Additionally, we explored how to integrate Python’s package manager, Pip, which is crucial for handling libraries and packages in Python.

As a final recommendation, it is prudent to regularly check for updates to Python and Pip, ensuring that you are always using the latest and most secure versions. This will keep your development environment robust and enhance the efficacy and security of your Python projects.

Share to...