Python 3.12 Installation on AlmaLinux 9 / RHEL 9

In this article, you will learn a complete guide on Python 3.12 Installation on AlmaLinux 9 / RHEL 9 including Rocky Linux 9 from Command Line Terminal. As you must know, Python is a great and popular programming language that can be used to build websites and software. At the current time, the latest stable version of Python is Python 3.12. You can follow the steps below to start Python 3.12 installation on RHEL 9 distros.

What Python version is supported by RHEL 9?

In RHEL 9, Python 3.9 is the default Python version. At this point, you can proceed to the following steps to get the latest stable version which is Python 3.12.

Complete Guide To Python 3.12 Installation on AlmaLinux 9 / RHEL 9

Before you start your Python 3.12 installation, you must have access to your server as a root or non-root user with sudo privileges. For this purpose, you can check the following AlmaLinux 9 and Rocky Linux 9 initial setup guides:

Initial Server Setup on AlmaLinux 9

Initial Server Setup on Rocky Linux 9

You can use any RHEL 9 distros for this guide. Here to show you the installation steps guide, we use AlmaLinux 9.

Step 1 – Install Required Packages for Python 3.12 on RHEL 9

First, you must run the system update with the command below:

sudo dnf update -y

Then, you need to install some required packages for your Python 3.12 on AlmaLinux 9 and RHEL 9 such as Rocky Linux 9:

sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make tar -y

Step 2 – Download Python 3.12 Package From Official Site

At this point, you must visit the Pyhotn Downloads page and get the latest stable version by using the following wget command on your RHEL 9 server:

sudo wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
Output
...
HTTP request sent, awaiting response... 200 OK
Length: 27195214 (26M) [application/octet-stream]
Saving to: ‘Python-3.12.0.tgz’

Python-3.12.0.tgz   100%[===================>]  25.93M  43.7MB/s    in 0.6s

2023-10-29 01:58:04 (43.7 MB/s) - ‘Python-3.12.0.tgz’ saved [27195214/27195214]

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

sudo tar -xf Python-3.12.0.tgz

Now switch to your Python 3.12 directory with the command below on RHEL 9:

cd Python-3.12.0

Step 3 – Build and Install Python 3.12 on AlmaLinux 9 / RHEL 9

At this point, you must run the following configuration script to be sure that all the dependencies work correctly for Python 3.12 installation:

sudo ./configure --enable-optimizations
Output
checking for stdlib extension module _testbuffer... yes
checking for stdlib extension module _testimportmultiple... yes
checking for stdlib extension module _testmultiphase... yes
checking for stdlib extension module xxsubtype... yes
checking for stdlib extension module _xxtestfuzz... yes
checking for stdlib extension module _ctypes_test... yes
checking for stdlib extension module xxlimited... yes
checking for stdlib extension module xxlimited_35... yes
...

Then, run the command below to find your number of system cores on RHEL 9:

sudo nproc
Output
2

Next, start your Python 3.12 build process by using the command below and define your number of cores with the -j option:

sudo make -j 2

This will take some time to complete. Then, use the command below to install Python 3.12 on AlmaLinux 9 and RHEL 9:

sudo make altinstall

Step 4 – Check and Verify Python 3.12 Installation on RHEL 9

When your installation is completed, you can verify your Python 3.12 installation on AlmaLinux 9 and RHEL 9 by checking its version:

python3.12 --version
Output
Python 3.12.0

To ensure that Python 3.12 is working correctly, you can create a test Python project.

First, you need to create the Python project directory and switch to it with the following command:

mkdir ~/test_app && cd ~/test_app

Then, from the project directory, create a virtual environment with the following command, we named it test_app_venv:

python3.12 -m venv test_app_venv

Next, activate your virtual environment with the command below:

source test_app_venv/bin/activate

You will see that your shell prompts changes to the name of your virtual environment.

For example, you can install Apache-Airflow inside your virtual environment with the pip package manager for Python:

pip install apache-airflow

Note: To get more information about pip and how to use it, you can visit this guide on Using pip to Install Python packages on Linux.

To exit from your virtual environment you can use the following command:

deactivate

Conclusion

At this point, you have learned to complete the Python 3.12 installation steps from the source on AlmaLinux 9 and RHEL 9 such as Rocky Linux 9. Also, you have learned to test your installation by making a test project. Hope you enjoy using it.

You may also like these articles:

Install Python 3.12 on Ubuntu and Debian Server

Execute Shell Commands in Python with Examples

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!