frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How To Install Python 3.12 on Ubuntu/Debian

Introduction

Python is one of the most widely used programming languages ​​today. Its main advantages are relative simplicity, low entry threshold, versatility in use, and a variety of plugins.

In this guide, we will install the Python 3.12 version on Ubuntu (starting from version 20.04) and Debian 11 and 12.

Please note: It is recommended to create a backup of your system before making significant changes, such as adding third-party repositories or installing software that could impact system dependencies.

Installation Guide

Update the system

Start by updating your system:

apt update -y && apt upgrade -y

Next, you need to install Python.

The steps to install Python on Ubuntu and Debian are different.

For Ubuntu

The deadsnakes PPA offers the latest Python versions for Ubuntu.

Note: The deadsnakes PPA provides newer Python versions, but it might introduce conflicts with the system Python. Be cautious when using it on applications relying on the default Python version.

1. Install Python Dependencies

Install essential tools for managing software properties.

apt install software-properties-common -y

2. Add the deadsnakes PPA

Add the repository providing the latest Python versions and update the package list:

add-apt-repository ppa:deadsnakes/ppa -y
apt update

3. Install Python 3.12:

Install Python version 3.12 from the added repository.

apt install python3.12 -y

For Debian

Debian does not support the deadsnakes PPA, so Python must be built from source.

1. Install Required Build Dependencies:

Install packages needed to build Python from source.

apt install -y wget build-essential zlib1g-dev libssl-dev libncurses5-dev libnss3-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

2. Download Python 3.12 Source Code:

Download the Python 3.12 source archive.

cd /usr/src
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz

3. Extract the Source Code:

Unpack the downloaded source code.

tar xzf Python-3.12.0.tgz
cd Python-3.12.0

4. Configure and Compile Python

Configure, compile, and install Python with optimizations:

./configure --enable-optimizations
make -j$(nproc)
make altinstall

The execution of these commands may take some time to complete.

Using make altinstall instead of make install is crucial to avoid overwriting the system Python binary (python3).

Set Python 3.12 As The Default Version (For both Ubuntu and Debian)

On Ubuntu 24.04, Python 3.12 is the default version, but on other distributions, you may need to make adjustments to set Python 3.12 as the default version.

To set Python 3.12 as the default python3 version, you need to update the python3 symlink.

Run this command:

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1

If you are getting an error, try this one:

update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.12 1

Then verify the default Python version:

python3 --version

You should see 12 version (the exact version depends on your distribution):

Python 3.12.0

Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2025 Time4VPS. All rights reserved.

Get In Touch