Skip to content

How to Install Python 3.12 on CentOS, RHEL & Fedora

Steps
8
Category
Python
Covers
CentOS, Fedora, RHEL
On this page 8 steps

Python, renowned for its simplicity and power, is a vital tool for developers and system administrators. With the release of Python 3.12, users of CentOS, RHEL, and Fedora can benefit from its latest features and improvements. This guide provides a comprehensive walkthrough for compiling and installing Python 3.12 on these Linux distributions.

Prerequisites

Before proceeding, ensure you have:

  • system running CentOS, RHEL, or Fedora.
  • Basic knowledge of terminal commands.
  • Sudo privileges or access to the root account.

Step 1 of 8Update Your System

Begin by updating your system packages to the latest versions. Open your terminal and execute:

sudo yum update 

Step 2 of 8Install Required Libraries

Python requires various development tools and libraries. Install them using:

sudo yum groupinstall 'Development Tools' 

Python depends on several libraries. Install them by running:

sudo yum install openssl-devel bzip2-devel libffi-devel sqlite-devel 

Step 3 of 8Download Python 3.12

Next, download the latest Python 3.12 source code from the official Python website. You can use wget:

wget https://www.python.org/ftp/python/3.12.1/Python-3.12.1.tgz 

Replace 3.12.1 with the latest minor version number.

Then extract the downloaded tarball using:

tar xzf Python-3.12.1.tgz 

Step 4 of 8Configure the Build Environment

Navigate to the Python source directory and run the configure script:

cd Python-3.12.1 
./configure --enable-optimizations 

The –enable-optimizations option optimizes the Python binary by running multiple tests, which might take some time.

Step 5 of 8Compile Python Source

Compile Python using the make command. To speed up the compilation process, you can use the -j option with the number of cores in your processor:

make -j 4 

Step 6 of 8Install Python

After compilation, install Python using:

sudo make altinstall 

Using altinstall prevents overwriting the default system Python.

Step 7 of 8Verify Python Installation

Check the Python version to verify the installation:

python3.12 --version 

Step 8 of 8Configure Pip (Optional)

If you need to manage Python packages, you can install pip:

python3.12 -m ensurepip --upgrade 

Conclusion

You’ve successfully compiled and installed Python 3.12 on your CentOS, RHEL, or Fedora system. This setup allows you to explore the newest features and enhancements of Python 3.12 while maintaining system stability. Remember to check the official Python documentation for more detailed information and updates on Python 3.12.

This guide outlines the critical Steps for compiling and installing Python 3.12. It ensures that even those new to Linux environments can follow along and upgrade their Python setup.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

1 Comment

  1. User
    ./configure ‘–enable-ipv6’ ‘–enable-shared’ ‘–with-computed-gotos=yes’
    ‘–with-dbmliborder=gdbm:ndbm:bdb’ ‘–with-system-expat’ ‘–with-system-ffi’
    ‘–enable-loadable-sqlite-extensions’ ‘–with-dtrace’
    ‘–with-ssl-default-suites=openssl’ ‘–without-ensurepip’
    ‘–enable-optimizations’ ‘CFLAGS=-O2 -g -pipe -Wall
    -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
    –param=ssp-buffer-size=4 -grecord-gcc-switches -m64
    -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv ‘
    ‘LDFLAGS=-Wl,-z,relro -g ‘
    ‘CPPFLAGS= ‘ ‘PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig’

    Instead of :
    ./configure –enable-optimizations

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top