Python 3.11 is recently launched with multiple improvement and security upgrades. This version provides developers to easily debug their code with fine-grained error locations in tracebacks. The new “Self” annotation provides a simple way to annotate methods that return an instance of their class.

Mostly the latest operating systems comes with the latest Python versions. But the OS versions released before the release of Python 3.11 may not have the latest version . This tutorial will help you to install Python 3.11 on your CentOS, Red Hat & Fedora operating systems by compiling it from source code.

Requirements

This Python installation required GCC compiler on your system. Login to your server using ssh or shell access. Now, use the following command to install prerequisites for Python before installing it.

sudo dnf install gcc openssl-devel bzip2-devel sqlite-devel 

Step 1: Download Python 3.11

Download Python using the following command from the Python official site. You can also download the latest version in place of specified below.

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

Now extract the downloaded package.

tar xzf Python-3.11.1.tgz 

Step 2: Install Python 3.11 on CentOS & Fedora

Use below set of commands to compile Python source code on your system using altinstall.

cd Python-3.11.1 
sudo ./configure --enable-optimizations 
sudo make altinstall 

make altinstall is used to prevent replacing the default python binary file /usr/bin/python .

Now remove downloaded source archive file from your system

sudo rm /usr/src/Python-3.11.1.tgz 

Step 3: Check Python Version

Check the latest version installed of python using below command.

python3.11 -V 

Python 3.11.1

Conclusion

In this tutorial, you have found the instructions to install Python 3.11 on CentOS, RHEL and Fedora systems by compiling it from the source code. We sill suggest to package manager for the Python installation, but if the package manager is failing to do it, compile it from source code.