How to install a current version of Python on Debian

The Python programming language is already pre-installed on Debian, but usually in an old version. A current version cannot be added from the standard repositories, but with a few shell commands you get a current version on your linux system.

Let’s start with the required packages and their dependencies:

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

Next, download the Python version you want to use (3.9.5 in this example):

$ wget https://python.org/ftp/python/3.9.5/Python-3.9.5.tgz

Unpack the tar archive with the following command:

$ tar xzf Python-3.9.5.tgz

Now change to the Python directory:

$ cd Python-3.9.5

and run the configure command to check the prerequisites for the build process:

$ ./configure --enable-optimizations

Now the build process follows. It is started with the following command:

$ make -j 2

The option -j 2 means the number of cores to be used. You can use the nproc command to find out how many cores are available.

Once the build process is complete, the binaries can be installed:

$ sudo make alt install

This will not create symbolic links for python3. Instead, this Python version can be started with python3.9. You should execute this command to determine whether the new version has been correctly installed on your system:

$ python3.9 --version
Python 3.9.5

By the way, the make install statement should not be used, as this will overwrite existing binaries.