Install Python 3.12 on Ubuntu and Debian Server

This guide intends to teach you to Install the LTS Python release which is Python 3.12 on Debian and Ubuntu server such as Debian 12 and 11, Ubuntu 22.04 and 20.04. The new release of Python 3.12 has many new features and optimizations and it is more flexible. Follow the steps below to get the installation step of Python 3.12 on Debian-based distros.

Steps To Install Python 3.12 LTS on Ubuntu and Debian Server

Before you start, you must have access to your server as a non-root user with sudo privileges. You can visit the Orcacore website and get the Debian and Ubuntu initial server setup guides.

Now follow the steps below to start your Python 3.12 installation.

Step 1 – Required Packages for Python 3.12 Installation on Ubuntu / Debian

First, you must run the system update and upgrade with the following commands:

# sudo apt update
# sudo apt upgrade

Then, you need the required packages and dependencies for Python 3.12 LTS installation on your Debian-based server. To do this, you can run the command below:

sudo apt install -y libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev wget build-essential libreadline-dev

When you are done, proceed to the next step to download the latest Python release on your server.

Step 2 – Download Python 3.12 Tarball package on Ubuntu / Debian

At this point, you must visit the Python Release page and get the Python 3.12 XZ tarball source package by using the following wget command:

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

When your download is completed, extract it with the following command:

sudo tar -xvf Python-3.12.0.tar.xz

Step 3 – Build and Install Python 3.12 on Ubuntu / Debian

Now you need to navigate to your Python directory with the command below:

cd Python-3.12.0/

Then, run the following configure command in the Python directory:

sudo ./configure --enable-optimizations

Next, use the following command to build and install your Python 3.12:

sudo make altinstall

It may take a little time to complete depending on your OS speed and internet.

Step 4 – Set Python 3.12 as the Default on Ubuntu / Debian

If you want to replace your previous version of Python with the newly installed Python release, you need to create a symbolic link for it. To do this, you can use the command below:

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

Verify your Python 3.12 installation by checking its version:

python3 --version
Ouput
Python 3.12.0

Step 5 – Launch Python 3.12 Shell

To start using Python, you need to run the Python 3.12 shell on Debian and Ubuntu. To do this, you can use the command below:

python3.12
Ouput
Python 3.12.0 (main, Oct 14 2023, 12:47:53) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

For example, you can run a simple Hello World project:

>>> print("Hello World, Python 3.12 is Amazing!")                                                                       
Hello World, Python 3.12 is Amazing!
>>>

Conclusion

At this point, you have learned to install the latest stable release of the Python programming language which is Pyhotn 3.12 on Ubuntu 22.04 and 20.04, Debian 12 and 11. It has a number of improvements, and several modules have better performance.

Hope you enjoy using it. You may be interested in these articles:

Use pip to Install Python packages on Linux

Install Anaconda Python on Debian 12 Bookworm

Execute Shell Commands in Python with Examples

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!