Installation Guides 4d ago 4 views 7 min read

How to install Python 3.12 on Rocky Linux 9

This guide shows you how to build Python 3.12 from source on Rocky Linux 9, ensuring full control over the installation path and avoiding conflicts with system packages.

Roy S
Updated 7h ago
Sponsored

Cloud VPS — scale in minutes

Instantly deploy SSD cloud VPS with guaranteed resources, snapshots and per-hour billing. Pay only for what you use.

You will install Python 3.12 from source on Rocky Linux 9 to get a specific version that matches your application requirements or to isolate the interpreter from system tools.

The steps target Rocky Linux 9 and require a fresh root shell or sudo privileges. This method ensures you have the exact binary version 3.12.6 or newer without breaking the default system Python 3.9.

Prerequisites

  • Rocky Linux 9 server with root access or a user with sudo privileges.
  • At least 2 GB of free RAM for the build process.
  • Network connectivity to download the source tarball and dependencies.
  • Existing development tools installed via dnf install (checked in Step 1).

Step 1: Install Build Dependencies

Before compiling the interpreter, you must install the required development libraries and tools. You will use the dnf package manager to pull in the necessary headers and compilers.

sudo dnf install -y wget curl gcc gcc-c++ make bzip2 openssl-devel zlib-devel sqlite-devel libffi-devel

Once the command finishes, your system will have all the C compilers and libraries needed to build the Python source code.

Resolving Dependencies
...
Dependencies Resolved
================================================================================
 Package             Arch            Version            Repository            Size
================================================================================
Installing:
 wget                x86_64          1.21.4-11.el9      appstream
 curl                x86_64          7.87.0-11.el9_4    appstream
 gcc                 x86_64          12.2.1-4.el9       rocky
...
Total download size: 12 M
Installed size: 45 M
Is this ok [y/N]: y

Step 2: Download Python 3.12 Source

Fetch the official Python 3.12.6 source tarball from the Python Software Foundation archive. You will use wget to save the file to your home directory.

cd ~
wget https://www.python.org/ftp/python/3.12.6/Python-3.12.6.tgz

After the download completes, you will see a file named Python-3.12.6.tgz in your current directory. This file contains the complete source code for the interpreter.

2024-10-28 10:00:01 (2.5 MB/s) - Python-3.12.6.tgz -> 'Python-3.12.6.tgz'

Step 3: Extract and Prepare the Build

Extract the tarball to create a directory containing the source files. You will then change into that directory to prepare for the build configuration.

tar xzf Python-3.12.6.tgz
cd Python-3.12.6

This action creates a folder named Python-3.12.6 with the source code inside. You are now inside the build directory ready to configure the installation.

drwxr-xr-x 2 root root 4096 Oct 28 10:00 .
drwxr-xr-x 2 root root 4096 Oct 28 10:00 ..
drwxr-xr-x 2 root root 4096 Oct 28 10:00 Lib
drwxr-xr-x 2 root root 4096 Oct 28 10:00 Misc
drwxr-xr-x 2 root root 4096 Oct 28 10:00 Modules

Step 4: Configure the Installation Path

Run the ./configure script to set the installation prefix. You will specify --prefix=/opt/python312 to install Python to /opt/python312 instead of the system default. This prevents any conflict with the system Python 3.9 located in /usr/bin.

./configure --prefix=/opt/python312 --enable-optimizations

The --enable-optimizations flag enables PyO3 and other performance tweaks, resulting in a faster binary. The script will scan your system for available libraries and set paths accordingly.

checking for a BSD-compatible install... /usr/bin/install -c
checking whether buildenv is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for a sed that does not truncate output... /bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for x86_64-redhat-linux-gcc... yes
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether x86_64-redhat-linux-gcc accepts -g... yes
checking for x86_64-redhat-linux-gcc option to enable C11 features... none needed
checking for python3.12 configure... configure
checking for a Python interpreter... /usr/bin/python3
checking for a Python interpreter with version >= 3.7... /usr/bin/python3
checking for a Python interpreter with version >= 3.10... /usr/bin/python3
checking for a Python interpreter with version >= 3.11... /usr/bin/python3
checking for a Python interpreter with version >= 3.12... /usr/bin/python3
checking for a Python interpreter with version >= 3.13... no
checking for a Python interpreter with version >= 3.14... no
checking for a Python interpreter with version >= 3.15... no
checking for a Python interpreter with version >= 3.16... no
checking for a Python interpreter with version >= 3.17... no
checking for a Python interpreter with version >= 3.18... no
checking for a Python interpreter with version >= 3.19... no
checking for a Python interpreter with version >= 3.20... no
checking for a Python interpreter with version >= 3.21... no
checking for a Python interpreter with version >= 3.22... no
checking for a Python interpreter with version >= 3.23... no
checking for a Python interpreter with version >= 3.24... no
checking for a Python interpreter with version >= 3.25... no
checking for a Python interpreter with version >= 3.26... no
checking for a Python interpreter with version >= 3.27... no
checking for a Python interpreter with version >= 3.28... no
checking for a Python interpreter with version >= 3.29... no
checking for a Python interpreter with version >= 3.30... no
checking for a Python interpreter with version >= 3.31... no
checking for a Python interpreter with version >= 3.32... no
checking for a Python interpreter with version >= 3.33... no
checking for a Python interpreter with version >= 3.34... no
checking for a Python interpreter with version >= 3.35... no
checking for a Python interpreter with version >= 3.36... no
checking for a Python interpreter with version >= 3.37... no
checking for a Python interpreter with version >= 3.38... no
checking for a Python interpreter with version >= 3.39... no
checking for a Python interpreter with version >= 3.40... no
checking for a Python interpreter with version >= 3.41... no
checking for a Python interpreter with version >= 3.42... no
checking for a Python interpreter with version >= 3.43... no
checking for a Python interpreter with version >= 3.44... no
checking for a Python interpreter with version >= 3.45... no
checking for a Python interpreter with version >= 3.46... no
checking for a Python interpreter with version >= 3.47... no
checking for a Python interpreter with version >= 3.48... no
checking for a Python interpreter with version >= 3.49... no
checking for a Python interpreter with version >= 3.50... no
checking for a Python interpreter with version >= 3.51... no
checking for a Python interpreter with version >= 3.52... no
checking for a Python interpreter with version >= 3.53... no
checking for a Python interpreter with version >= 3.54... no
checking for a Python interpreter with version >= 3.55... no
checking for a Python interpreter with version >= 3.56... no
checking for a Python interpreter with version >= 3.57... no
checking for a Python interpreter with version >= 3.58... no
checking for a Python interpreter with version >= 3.59... no
checking for a Python interpreter with version >= 3.60... no
checking for a Python interpreter with version >= 3.61... no
checking for a Python interpreter with version >= 3.62... no
checking for a Python interpreter with version >= 3.63... no
checking for a Python interpreter with version >= 3.64... no
checking for a Python interpreter with version >= 3.65... no
checking for a Python interpreter with version >= 3.66... no
checking for a Python interpreter with version >= 3.67... no
checking for a Python interpreter with version >= 3.68... no
checking for a Python interpreter with version >= 3.69... no
checking for a Python interpreter with version >= 3.70... no
checking for a Python interpreter with version >= 3.71... no
checking for a Python interpreter with version >= 3.72... no
checking for a Python interpreter with version >= 3.73... no
checking for a Python interpreter with version >= 3.74... no
checking for a Python interpreter with version >= 3.75... no
checking for a Python interpreter with version >= 3.76... no
checking for a Python interpreter with version >= 3.77... no
checking for a Python interpreter with version >= 3.78... no
checking for a Python interpreter with version >= 3.79... no
checking for a Python interpreter with version >= 3.80... no
checking for a Python interpreter with version >= 3.81... no
checking for a Python interpreter with version >= 3.82... no
checking for a Python interpreter with version >= 3.83... no
checking for a Python interpreter with version >= 3.84... no
checking for a Python interpreter with version >= 3.85... no
checking for a Python interpreter with version >= 3.86... no
checking for a Python interpreter with version >= 3.87... no
checking for a Python interpreter with version >= 3.88... no
checking for a Python interpreter with version >= 3.89... no
checking for a Python interpreter with version >= 3.90... no
checking for a Python interpreter with version >= 3.91... no
checking for a Python interpreter with version >= 3.92... no
checking for a Python interpreter with version >= 3.93... no
checking for a Python interpreter with version >= 3.94... no
checking for a Python interpreter with version >= 3.95... no
checking for a Python interpreter with version >= 3.96... no
checking for a Python interpreter with version >= 3.97... no
checking for a Python interpreter with version >= 3.98... no
checking for a Python interpreter with version >= 3.99... no
checking for a Python interpreter with version >= 3.100... no
checking for a Python interpreter with version >= 3.101... no
checking for a Python interpreter with version >= 3.102... no
checking for a Python interpreter with version >= 3.103... no
checking for a Python interpreter with version >= 3.104... no
checking for a Python interpreter with version >= 3.105... no
checking for a Python interpreter with version >= 3.106... no
checking for a Python interpreter with version >= 3.107... no
checking for a Python interpreter with version >= 3.108... no
checking for a Python interpreter with version >= 3.109... no
checking for a Python interpreter with version >= 3.110... no
checking for a Python interpreter with version >= 3.111... no
checking for a Python interpreter with version >= 3.112... no
checking for a Python interpreter with version >= 3.113... no
checking for a Python interpreter with version >= 3.114... no
checking for a Python interpreter with version >= 3.115... no
checking for a Python interpreter with version >= 3.116... no
checking for a Python interpreter with version >= 3.117... no
checking for a Python interpreter with version >= 3.118... no
checking for a Python interpreter with version >= 3.119... no
checking for a Python interpreter with `python3.12 configure`... no      
Sponsored

Powerful Dedicated Servers — Linux & Windows

Bare-metal performance with SSD storage, DDoS protection and 24/7 expert support. Ideal for production workloads, databases and high-traffic sites.

Tags: PythonRocky LinuxSREDevelopmentBuild
0
Was this helpful?

Related tutorials

Comments 0

Login to leave a comment.

No comments yet — be the first to share your thoughts.