how to change python version on Debian 12

Debian 12 comes with Python 3 by default, but sometimes you need to use a different version — for compatibility, development, or running specific tools.

Step 1: Check current version

Start by checking which version of Python 3 is active on your system:

python3 --version

Debian 12 typically ships with Python 3.11 or similar, but some tools may require older or newer versions.

Step 2: Install the new version

You can install additional versions (like Python 3.9 or 3.11) using the package manager or from source.

To install a version from APT:

sudo apt install python3.11 -y

If the version you want isn’t available in the default repo, you may need to add a PPA or compile from source.

Step 3: Configure alternatives

Debian allows you to manage multiple versions using the update-alternatives system.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1

If another version (like Python 3.9) is already installed, you can register it too:

sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2

This doesn’t override or break the system — it simply registers both versions.

Step 4: Switch the default version

Now you can switch between installed Python versions interactively.

sudo update-alternatives --config python3

You’ll see a list like:

There are 2 choices for the alternative python3:
  0    /usr/bin/python3.11   auto mode
  1    /usr/bin/python3.11   manual mode
  2    /usr/bin/python3.9    manual mode
Press enter to keep the current choice[*], or type selection number:

Choose the number for the version you want to set as default.

Step 5: Verify the change

After switching, confirm that the correct version is now in use:

python3 --version

You should see the version you selected in the previous step.

Share:

More Posts

How to Install Maven on macOS 2025

What you will read?1 Check for Java Installation2 Install Homebrew (If Not Installed)3 Install Maven via Homebrew4 Verify Environment Variables (Optional)5 Create a Sample Maven

How to Use Google SMTP Server

What you will read?1 Step 1: Enable SMTP Access in Gmail2 Step 2: Secure Connection with TLS3 Step 3: Send an Email via SMTP4 Step

how to install wine on RHEL

What you will read?1 Check RHEL version and CPU architecture2 Update system and install base tools3 Verify subscription and enable CodeReady Builder4 Enable EPEL repository5

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments