Jul 10, 2024 7 min read

How to Install Python 3.8 on Debian 12

Install Python 3.8 on Debian 12 with our step-by-step tutorial. Python is a popular programming language known for its simplicity and versatility.

Install Python 3.8 on Debian 12
Install Python 3.8 on Debian 12
Table of Contents


Before we begin talking about how to install Python 3.8 on Debian 12, let's briefly understand – What is Python?

Python is a popular programming language known for its simplicity and versatility. It provides a clear syntax that is easy to understand, making it an ideal choice for beginners. Python enables developers to write concise and readable code, reducing development time and increasing productivity.

With its vast library ecosystem, Python offers various ready-to-use tools and frameworks, empowering developers to create robust applications effortlessly. Whether you're a beginner or an experienced programmer, Python's flexibility and user-friendly nature make it a fantastic language for all.

In this tutorial, you will install Python 3.8 on Debian 12. We will also address a few FAQs on how to install Python 3.8 on Debian 12.

Advantages of Python

  1. Syntax Simplicity: Python 3.8 offers a clear and readable syntax, making it easy to learn and write efficient code.
  2. Versatility: Python 3.8 can be used for web development, data analysis, machine learning, automation, and more, making it a versatile language.
  3. Increased Performance: Python 3.8 introduces performance optimizations, resulting in faster execution and improved efficiency.
  4. Enhanced Features: Python 3.8 includes new features like assignment expressions, f-strings, and better error handling, enhancing developer productivity.
  5. Extensive Library Ecosystem: Python 3.8 comes with a vast collection of libraries and frameworks, offering ready-to-use tools for various purposes, fostering rapid development.

Install Python 3.8 on Debian 12 via the source

This section will walk you through the process of compiling the source code for Python 3.8 and installing it on Debian 12. You have the greatest control over the installation with this method. It guarantees that you receive the most recent version of Python, since as of right now, Python 3.8 is not even included in the default archives of Debian 11 Bullseye and Debian 12 Bookworm.

Step 1: Update Debian Packages Before Python 3.8 Installation

Before beginning the installation, it is wise to make sure your Debian system is up-to-date. Making sure the current packages and the ones we install are compatible is the goal of this step.

sudo apt update && sudo apt upgrade

Step 2: Install Development Packages for Python 3.8 Installation

We will install a few packages in this step that are necessary for building Python from source. These consist of additional tools and development libraries needed for compilation.

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.8 Source Code on Debian

Now go to the official Python website and download the Python 3.8 source code. Verify that you are running the most recent version by visiting the official downloads page. Python 3.8.17 is the most recent security release as of this writing.

wget https://www.python.org/ftp/python/3.8.17/Python-3.8.17.tar.xz

Step 4: Extract Python Archive and Move to Appropriate Directory

We must extract the source code after downloading it. In this case, extraction is done using the tar command.

tar -xf Python-3.8.12.tar.xz

Moving the extracted files to a common location inside /usr/local/ is a good idea for organizing purposes. We're going to relocate them to /usr/local/share in this guide.

mv Python-3.8.17 /usr/local/share/python3.8

Step 5: Configure, Compile, and Install Python 3.8 on Debian

Go to the directory where the Python source code is located now. The ./configure script will be executed with specific flags to enable shared libraries and perform optimizations.

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

The --enable-optimizations flag instructs the script to run numerous tests to optimize the Python binary and to make sure all dependencies are present. For some kinds of applications, shared libraries must be built using the --enable-shared.

You might also think about installing the pip package manager alongside Python by using the --with-ensurepip=install flag.

It's now time to use the make command to compile the source code.


Use the -j flag followed by the number of CPU cores you wish to use for faster compilation, especially on systems with multiple CPU cores. If your system has 06 CPU cores, for instance, you could use 05 of them:

make -j 5

Install the Python binaries after the compilation is finished. The make altinstall command is advised in order to prevent overwriting the system's default Python binary.

sudo make altinstall

Configure the run-time bindings for the dynamic linker after installation. This is a crucial step that you shouldn't skip because failing to do so could cause problems.

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

Step 6: Verify Python 3.8 Installation on Debian

Let's check the Python version lastly to confirm the installation. To ensure that Python 3.8 was installed successfully and is operational, this step is essential.

python3.8 --version

Create a Test Virtual Environment on Debian 12

We'll use Python 3.8 to set up a virtual environment in this section. Because they isolate dependencies specific to a project and prevent potential conflicts with other Python projects or system libraries, virtual environments are a recommended practice in Python development.

Step 1: Create a Test Project Directory

To begin with, we need to make a directory to house our Python project. We're going to set up our virtual environment here. To create and navigate through a directory called test_app, run the following commands:

mkdir ~/test_app
cd ~/test_app

Step 2: Create a Virtual Environment

Having obtained the project directory, let us proceed to establish a virtual Python environment. The venv module for Python, which is pre-installed in Python 3.3 and later versions, will be used. The creation of lightweight virtual environments is aided by this module.

To establish a virtual environment called test_app_venv, execute the following command:

python3.8 -m venv test_app_venv

The -m venv in this case denotes the use of the venv module. The virtual environment is called test_app_venv, but you can rename it to anything makes sense for your project.

Step 3: Activating the Python Virtual Environment on Debian

Activating the virtual environment is the next step after it has been created. The virtual environment can be isolated by turning it on, so any Python commands or packages you install will only run in this environment.

Activate the Python environment:

source test_app_venv/bin/activate

Its name will now show up to the left of the terminal prompt, indicating that you are in the virtual environment. For example:

(test_app_venv) user@debian:~/test_app$

This shows that the test_app_venv virtual environment is what you are currently using. You will only be able to access any Python packages you install in this environment.

Step 4: Deactivating the Virtual Environment on Debian

When you're done using the virtual environment, you can turn it off to go back to the Python environment that runs on the entire system.

All you have to do is type this:


You will no longer be in the virtual environment once the prefix in the terminal prompt vanishes after it has been deactivated.

Install Pip on Debian 12

The installation of Python 3.8 and Pip, the package manager for Python, will be the main topic of this section. Pip makes it easier to install and manage Python packages, making it a vital tool for Python developers.

Step 1: Verifying the Installation of Pip on Debian

Pip is usually included in Python 3.8. Use the following command to see if it's present:

python3.8 -m pip --version

If Pip's version is displayed by this command, it is installed. If not, move on to the manual installation steps below.

Step 2: Download the Pip Installation Script on Debian

We will download a Python script to control the installation process in order to install Pip for Python 3.8. The wget command can be used to download this script, get-pip.py.

Run the command below to obtain the Pip installation script:

wget https://bootstrap.pypa.io/get-pip.py

The get-pip.py script is retrieved from the official repository and saved in the current directory by using this command.

Step 3: Install Pip for Python 3.8 on Debian 12

It's now possible to install Pip after downloading the script. To use Python 3.8 to run the get-pip.py script, run the following command:

python3.8 get-pip.py

With this command, Python 3.8 is instructed to run the script and install Pip.

Upgrade Pip to the Latest Version

Make sure you're always running the most recent Pip version. Pip should be updated with:

python3.8 -m pip install --upgrade pip

This updates to the most recent version using Pip, which is available in Python 3.8.

FAQs to Install Python 3.8 on Debian 12

Can I have multiple Python versions installed on Debian 12?

Yes, Debian 12 allows you to have multiple Python versions installed alongside each other using the appropriate installation methods.

How do I check if Python 3.8 is installed on Debian 12? 

You can verify if Python 3.8 is installed on Debian 12 by using the terminal and checking the version information.

Are there any dependencies required for Python 3.8 installation on Debian 12?

Python 3.8 may have dependencies that need to be resolved during installation. The package manager will take care of these dependencies automatically.

Can I upgrade Python 3.8 to future versions easily? 

Upgrading Python versions on Debian 12 depends on the availability of newer packages. Upgrades can typically be managed through the package manager.

Is Python 3.8 compatible with existing Python packages on Debian 12? 

Python 3.8 is generally compatible with existing Python packages on Debian 12. However, you may need to ensure that your packages are updated and compatible with the Python 3.8 version.

Can I switch between different Python versions easily? 

Switching between different Python versions can be facilitated through the use of tools or methods provided by your distribution, allowing you to select the desired Python version.

Is Python 3.8 compatible with existing Python packages on Debian 12? 

Python 3.8 is generally backward compatible, but some packages may require updates. Use pip to ensure your packages are compatible with Python 3.8.


We hope this tutorial helped you understand how to install Python 3.8 on Debian 12.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.