Install Python 12 on AlmaLinux 9

By Raman Kumar

Updated on Dec 20, 2024

In this tutorial, we'll learn how to install Python 12 on AlmaLinux 9 using source code.

Python 12 is the latest stable version of the popular programming language, and installing it from the source allows you to have full control over the installation process and configure the environment as needed. This guide will walk you through each step, from setting up the necessary dependencies to downloading and compiling the source code, and finally verifying the installation.

Whether you are a developer looking for the latest features or a system administrator setting up Python on a server, this post will help you seamlessly integrate Python 12 into your AlmaLinux 9 environment. This is the most direct and reliable way to install Python 3.12 if it's not available in the default repository.

Prerequisites

Before you begin using the sftp command, ensure the following:

  • A KVM VPS or dedicated server with AlmaLinux 9 installed.
  • SSH Access: You must have SSH access to the remote system.
  • A root user access or normal user with administrative privileges.

Install Python 12 on AlmaLinux 9

Step 1: Install Dependencies

First, install the necessary build dependencies:

sudo dnf groupinstall "Development Tools" -y
sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel -y

Step 2: Download Python 3.12 Source

Next, download the Python 3.12 source code from the official Python website.

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

Step 3: Extract the Source Code

After downloading the tarball, extract it:

sudo tar xzf Python-3.12.3.tgz

Step 4: Compile and Install Python 3.12

Navigate to the extracted directory and compile Python 3.12:

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

Using altinstall ensures that it won’t overwrite the system’s default python or python3 binary.

Step 5: Verify Installation

Once the installation is complete, check the Python version:

python3.10 --version

You should see Python 3.10.x.

Conclusion

In this tutorial, we've learnt how to install Python 12 on AlmaLinux 9 using source code. Installing Python 12 from source on AlmaLinux 9 gives you greater flexibility and control over your Python environment, ensuring you're working with the latest version tailored to your needs. 

By following the steps outlined in this guide, you can successfully compile and install Python 12, enabling you to take advantage of its new features and improvements. Whether you're a developer or system administrator, mastering this installation process will help you keep your system up-to-date and ready for any Python-based projects.