How to Install Python 3.10 (or 3.11) on CentOS

How to Install Python on CentOS

In this tutorial, we’re going to show you how to install Python (the latest version) on CentOS with step-by-step instructions. This tutorial includes instructions for Python 3.10 and Python 3.11 on CentOS 7 and CentOS 8.

Alternative tutorial: How to install Python on Ubuntu.

Prerequisites

This is what you’ll need for this tutorial:

  • Root access or a user with sudo privileges
  • SSH access to the server, or just use Terminal if you’re on a desktop
  • A CentOS system. This tutorial will work for CentOS 7, CentOS 8, AlmaLinux, Rocky Linux, and other RHEL-based distros.
  • If you need a server, you can get one from Linode, or choose another Linux VPS provider.

On some systems, Python may already be installed. To check what version of Python you have installed (if any), run the following commands:

python -V
python3 -V

If Python is installed, one or both commands will give you an output of the version that’s installed.

Recommended read: Best Linux Distro for Programming

Default Versions of Python in CentOS

Depending on when you’re reading this or what version you’re using, the version that you have installed by default or the version that’s available in the CentOS repo might be different.

For CentOS 7:

  • Python 2.7.5 is installed by default. That version has reached its EOL years ago, so you should upgrade ASAP.
  • Python 3.6.8 is the latest version available in the CentOS 7 repos. 3.6 reached its EOL in Dec 2021, so you should upgrade ASAP.

For CentOS 8:

  • Python isn’t installed by default.
  • Python 3.9.6 is the latest version available in the CentOS 8 repos. The EOL of Python 3.9.6 is Oct 2025, so you can use that version. To install it, just run yum install python39 and that’s it. If you want to install Python 3.10 or 3.11, follow the tutorial below.

How to Install Python 3.10 on CentOS

Now, onto our tutorial on how to install Python 3.10 on CentOS (any version)

Step 1: Update CentOS

The first step, as always, is to update your system with the following command:

yum update

Step 2: Install necessary packages

Next, we need to install some packages:

yum install openssl-devel bzip2-devel libffi-devel
yum groupinstall "Development Tools"

Step 3: Download Python

First, get the download link for the version of Python that you plan on installing from this page. In this tutorial, we’ll be using Python 3.10.2.

Download the file with the command below:

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

And extract the archive with:

tar -xzf Python-3.10.2.tgz

Step 4: Install Python 3.10

To install the Python version you just downloaded, cd into the directory:

cd Python-3.10.2

Then, run the following command:

./configure --enable-optimizations

And finally, compile Python (without replacing the default version):

make altinstall

This process might take a while. After it’s done, you can verify if you installed Python 3.10.2 with the following command:

python3.10 -V

Which should return the exact version of Python (3.10.2)

How to Install Python 3.11 on CentOS

The instructions are pretty similar to 3.10.

Step 1: Update CentOS

The first step, as always, is to update your system with the following command:

yum update

Step 2: Install necessary packages

Next, we need to install some packages:

yum install openssl-devel bzip2-devel libffi-devel
yum groupinstall "Development Tools"

Step 3: Download Python

First, get the download link for the version of Python that you plan on installing from this page. In this tutorial, we’ll be using Python 3.11.0a4

Download the file with the command below:

wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0a4.tgz

And extract the archive with:

tar -xzf Python-3.11.0a4.tgz

Step 4: Install Python 3.11

To install the Python version you just downloaded, cd into the directory:

cd Python-3.11.0a4

Then, run the following command:

./configure --enable-optimizations

And finally, compile Python (without replacing the default version):

make altinstall

This process might take a while. After it’s done, you can verify if you installed Python 3.11.0a4 with the following command:

python3.11 -V

Which should return the exact version of Python (3.11.0a4).

And that’s it. You’ve now installed the latest version of Python on CentOS.

By Linux Stans

The official Linux Stans account.

17 comments

  1. How would I go about uninstalling 3.10, especially if done with altinstall? I was going through the makefile and i don’t think this was in it

  2. Also when looking through the makefile, I didn’t get to see anything for uninstall. How would I go about uninstalling 3.10 after make altinstall?

  3. pip does not work following the instructions above.
    When I issue the command ‘pip3 install websockets’
    I get this error:
    Could not fetch URL https://pypi.org/simple/websockets/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=’pypi.org’, port=443): Max retries exceeded with url: /simple/websockets/ (Caused by SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)) – skipping

    1. I tried running the exact steps from the tutorial again and installed pip3 and websockets. It all worked fine:

          9  yum install epel-release
         10  yum install python3-pip
         11  pip3 install websockets
         12  history
      

      Can you double-check if you’ve installed “openssl-devel”?

  4. This does not work, at least not on CentOS 7. If you perform the steps advised, it will appear to install, but all you need to do is run “pip install –upgrade pip” and you’ll get errors that OpenSSL is not installed. This is the issue I was trying to resolve when I found this page. These instructions are incomplete.

    1. I should have mentioned: thanks to the earlier poster for suggesting python3-pip. Using pip version 3.6 might do the trick for us, but it doesn’t address the main issue of getting pip 3.10 to work (we’re trying 3.10.4 and 3.10.5).

  5. My Error:
    ———————————————————-
    WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

    WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(“Can’t connect to HTTPS URL because the SSL module is not available.”)’: /simple/pip/

    What fixed my issue:
    ———————————————————-
    sudo yum install openssl11 openssl11-devel
    mkdir /usr/local/openssl11
    cd /usr/local/openssl11
    ln -s /usr/lib64/openssl11 lib
    ln -s /usr/include/openssl11 include

    Then proceed with the original steps in this guide, changing the “./configure –enable-optimizations” to point to the new OpenSSL:
    ./configure –with-openssl=/usr/local/openssl11

    Hope this works for someone out there struggling! I’m running CentOS 7.9.2009 – Core and was doing the Python3.10 install (3.10.2)

    1. OOOOOH MY GOD!

      After 3 hours and over a dozen “right answers” across stack overflow and here, you finally gave me the one that works on Centos 7 and python 3.10 (and openssl, which WAS installed by the system but python cannot see it. This is a major design bug in python itself, the sort that can turn good folks away from python)

    2. Excellent suggestion. I was installing 3.11.1 on CentOS 7.8.2003.
      Seems to make the build work with OpenSSL support.

        1. install the pre-reqs as above and then

          (as root)
          yum install openssl11 openssl11-devel -y
          mkdir /usr/local/openssl11
          cd /usr/local/openssl11
          ln -s /usr/lib64/openssl11 lib
          ln -s /usr/include/openssl11 include
          cd /usr/src
          wget https://www.python.org/ftp/python/3.10.13/Python-3.10.13.tgz
          tar xvf Python-3.10.13.tgz
          cd Python-3.10.13
          ./configure –enable-optimizations –with-openssl=/usr/local/openssl11
          make altinstall

  6. Hi, this fails for me during make with “ModuleNotFoundError: No module named ‘encodings'”. The error is triggered by _bootstrap_python. I’ve tried building inside a virtual environment and outside. My environment is

    PYTHONHOME = (not set)
    PYTHONPATH = (not set)
    program name = ‘./_bootstrap_python’
    isolated = 0
    environment = 0
    user site = 0
    import site = 1
    is in build tree = 0
    stdlib dir = ‘/usr/local/lib/python3.11’
    sys._base_executable = ‘/bin/_bootstrap_python’
    sys.base_prefix = ‘/usr/local’

    This is on Centos 7 (which came with python 3.6.8 installed).

Leave a Reply to Mark Rogers Cancel reply

Your email address will not be published. Required fields are marked *

Exit mobile version