0%

​Objective: Install Python 3.10 or later on CentOS 7 while preserving the system-default Python 2.7 environment.

​Step 1: Install Required Dependencies

1
2
sudo yum groupinstall -y "Development Tools"
sudo yum install -y openssl-devel bzip2-devel libffi-devel zlib-devel ncurses-devel sqlite-devel readline-devel tk-devel

Step 2: Download Python 3.10 Source Code

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

Step 3: Extract and Configure the Source Code

1
2
tar xzf Python-3.10.0.tgz
cd Python-3.10.0

Configure the build with optimizations and a custom installation path:

1
./configure --enable-optimizations --prefix=/usr/local

./configure –enable-optimizations –prefix=/usr/local

Step 4: Compile and Install Python

1
sudo make altinstall

Step 5: Verify Installation

1
python3.10 --version

Expected output: Python 3.10.0

If you want to use python3 as a shortcut for python3.10, follow these steps:

1. Check the Python 3.10 Installation Path

By default, Python 3.10 is installed to /usr/local/bin/python3.10. Verify this:

1
ls /usr/local/bin/python3.10

1
sudo ln -s /usr/local/bin/python3.10 /usr/bin/python3
3. Verify the Link​

Check the new symlink and version:

1
2
ls -l /usr/bin/python3  # Should point to /usr/local/bin/python3.10
python3 --version # Should show "Python 3.10.x"