- Update your system's package index:
sudo yum update
- Install the required packages for building Python from source:
sudo yum install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel readline-devel sqlite-devel
- Download the source code for Python 3.10 (or 3.11) from the official Python website:
wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tar.xz
- Extract the source code:
tar -xf Python-3.10.0.tar.xz
- Navigate to the extracted directory:
cd Python-3.10.0
- Configure the build:
./configure --enable-optimizations
- Compile Python:
make -j $(nproc)
The -j
flag specifies the number of CPU cores to use during the compilation process. nproc
returns the number of available CPU cores on the system.
- Install Python:
sudo make altinstall
The altinstall
target installs Python as a separate version, rather than replacing the system's default Python.
- Verify that Python is installed and working correctly:
python3.10 --version
This should output the version number of Python 3.10 that you just installed.