Install Python 3.11.9 on CentOS and replace the default Python version in your system, you can follow the steps below. Note that replacing the default Python version may affect other tools and dependencies on the system, so please be cautious.
Step 1: Install dependencies
First, make sure the system has the dependencies required to compile Python:
sudo yum groupinstall -y "Development Tools" sudo yum install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel
Step 2: Download and decompress the Python 3.11.9 source code
GoPython official download pageDownload the source code package of Python 3.11.9, or use the following command to download and decompress:
cd /usr/src wget /ftp/python/3.11.9/Python-3.11. tar -xJf Python-3.11. cd Python-3.11.9
Step 3: Compile and install Python
Compile and install Python 3.11.9:
./configure --enable-optimizations make -j $(nproc) sudo make altinstall
Notice:We use
make altinstall
Insteadmake install
to avoid covering the system's ownpython
Binary file. After the installation is completed, Python 3.11.9 willpython3.11
The form of/usr/local/bin/
In the directory.
Step 4: Update the default Python version
replacepython3
Symbol links
Make the default systempython3
Link to a newly installed Python 3.11.9:
sudo ln -sf /usr/local/bin/python3.11 /usr/bin/python3
replacepip3
Symbol links
Similarly,pip3
Link to Python 3.11.9 version:
sudo ln -sf /usr/local/bin/pip3.11 /usr/bin/pip3
Step 5: Verify the installation
Check Python version:
python3 --version pip3 --version
Python 3.11.9 and corresponding should be outputpip
Version information.
Things to note
-
System compatibility: Many system tools for CentOS (e.g.
yum
) Rely on Python. - Direct replacement
/usr/bin/python
This may cause system tool exceptions. Therefore, it is recommended to only modifypython3
Link, and keep/usr/bin/python
Point to Python.
Create a virtual environment: If your project or tool requires a different Python version or module, it is recommended to use itvirtualenv
orvenv
Create an isolated environment to reduce dependency on the Python version of the system.
This is the end of this article about the complete process of installing Python 3.11.9 in CentOS. For more related Python 3.11.9 installation content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!