Menu
User

DropVPS Team

Writer: Cooper Reagan

How to Change Python Version in CentOS 8

How to Change Python Version in CentOS 8

Publication Date

06/17/2025

Category

Articles

Reading Time

2 Min

Table of Contents

First, check the current version of Python on your system:

python3 --version

CentOS 8 comes with Python 3.6 by default. If you need a newer version like Python 3.9 or 3.11, here’s how to change it safely without breaking system tools that rely on the default Python interpreter.

Step 1: Install Required Packages

Make sure your system is updated and essential tools are installed:

sudo dnf update -y
sudo dnf groupinstall "Development Tools" -y
sudo dnf install gcc openssl-devel bzip2-devel libffi-devel wget make -y

Step 2: Download the Desired Python Version

You can download Python source code from the official website. For example, to install Python 3.11.4:

cd /usr/src
sudo wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz
sudo tar xzf Python-3.11.4.tgz
cd Python-3.11.4

Step 3: Compile and Install

Use make altinstall instead of make install to avoid overwriting the system’s default Python binary.

sudo ./configure --enable-optimizations
sudo make altinstall

Once completed, confirm the new version:

python3.11 --version

Step 4: Set the Default Python Version (Optional)

If you want to switch the default python3 command to the new version:

sudo alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.11 2

Then choose the default:

sudo alternatives --config python3

Select the desired version from the menu.

Step 5: Update pip (If Needed)

Sometimes pip is not installed by default. You can install or upgrade it with:

python3.11 -m ensurepip
python3.11 -m pip install --upgrade pip

Now pip is ready to use with Python 3.11.

Step 6: Avoid Breaking System Tools

Important: Don’t replace /usr/bin/python or remove Python 3.6. Many CentOS system utilities depend on it. Stick to using python3.11 or configure virtual environments for your projects.

If you’re using virtualenv:

python3.11 -m venv myenv
source myenv/bin/activate

Now you’re working in a clean, isolated environment with your selected Python version.

Linux VPS
U
Loading...

Related Posts

How to Change Python Version in CentOS 8