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: Update Your System
Begin by updating your system packages to the latest versions. Open your terminal and execute:
sudo yum update
Step 2: Install 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: Download 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: Configure 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: Compile 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: Install Python
After compilation, install Python using:
sudo make altinstall
Using altinstall prevents overwriting the default system Python.
Step 7: Verify Python Installation
Check the Python version to verify the installation:
python3.12 --version
Step 8: Configure 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.