How to Install Python on CentOS

How to Install Python 3.10 (or 3.11) 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.

How to Install Python on Ubuntu

How to Install Python on Ubuntu

In this tutorial, we’re going to show you how to install the latest version of Python on Ubuntu. Step-by-step, beginner-friendly instructions.

Leave a comment

Your email address will not be published.

3 thoughts on “How to Install Python 3.10 (or 3.11) on CentOS”