09.06.2023

Installing the latest version of Python on Debian

Python is a popular programming language at the present time due to its speed, portability of programs written in it, and a relatively low entry threshold for novice developers. The material below will describe the process of upgrading to version 3.10.9 of this language packages on a host running Debian OS.

Updating the system software of the operating system

We will execute all commands as the root user, for this we execute: sudo -i First of all, let's update the OS itself:

apt-get install sudo -y
apt-get install aptitude
aptitude update
aptitude upgrade

After the OS update is complete, let's look at the current available language support libraries:

Python3 -V

Install dependent software, compile

sudo apt install wget software-properties-common
apt-get install build-essential
aptitude install build-essential libncursesw5-dev libreadline-gplv2-dev libssl-dev libsqlite3-dev tk-dev libc6-dev libbz2-dev libffi-dev -y

Download the actual file, unpack it to an arbitrary location:

wget https://www.python.org/ftp/python/3.11.3/Python-3.11.3.tgz
tar xvf Python-3.11.3.tgz

Moving to location:

cd Python-3.11.3/

Then we compile:

./configure --enable-optimizations

And then install:

make install

Check if the update is correct

Insert this:

python3 -V

You can also check by creating a simple script and running it:

touch test.py

Let's make it executable:

chmod +x test.py

Let's paste the contents into this file :

echo "print('Hello, world')">test.py

And let's run:

/usr/bin/python3 test.py

As a result, a message will be displayed on the screen.

Hello, world

Removing temporary files

If there is no need for previously downloaded archive files, they can be deleted as follows:

cd .. Rm -rf Python-3.1.* sudo aptitude clean

Outcome

Now ready to use the updated version of Python on the server.

You may be also interested in