Menu
User

DropVPS Team

Writer: John hens

how to change python version on Debian 12

how to change python version on Debian 12

Publication Date

07/26/2025

Category

Articles

Reading Time

2 Min

Table of Contents

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.

Linux VPS
U
Loading...

Related Posts