How to Install Python On Centos 7 and 8 ?

If you happen to be using CentOS 7 or 8 and are eager to embark on the journey of how to install Python on centos 7 and 8 system, you’ve landed in the ideal destination. Throughout this tutorial, we’ll guide you through an in-depth procedure to have Python installed and operational on your CentOS machine. Whether you’re a novice or a seasoned developer, let’s plunge in and embark on this journey of installing Python hand in hand.

Install Python On Centos 7 & 8

Before we begin installing Python, let’s make sure our CentOS system is ready. Open a terminal with administrative privileges and follow these steps:

Update the system packages by executing the following command:

sudo yum update

It’s important to check if your CentOS system already has Python installed. Execute the following command in the terminal:

python --version

If Python is already installed, the version number will be displayed. Proceed to the next step if no version is shown.

Installing Required Dependencies

To successfully build and install Python, we need to install some necessary dependencies. Run the following command to install the required packages:

sudo yum install gcc openssl-devel bzip2-devel libffi-devel

Downloading the Python Installation Package

Visit the official Python ftp website and choose the latest stable release of Python and copy the download link for the source code package. In our case its Python-3.9.8.tgz.

Back in the terminal, use the wget command followed by the copied link to download the Python installation package. For example:


Replace the /3.9.8/Python-3.9.8.tgz with your chosen version.

Extracting and Navigating to the Python Directory

Once the download is complete, we need to extract the package and navigate to the Python directory. Execute the following commands:

tar -xvf Python-*.tgz
cd Python-*

Configuring Python Build Options

Before we start the build process, it’s important to configure Python based on our system. Use the following command to configure the build:

./configure --enable-optimizations

By including the --enable-optimizations flag, we enable additional optimizations that can improve the performance of Python.

Compiling and Installing Python

Now that we have configured Python, it’s time to compile and install it on your CentOS system. Execute the following command:


This command compiles the Python source code and prepares it for installation.

Next, install Python by running the command:

sudo make altinstall

Using make altinstall instead of make install prevents any conflicts with the existing Python installation on your system.

Congratulations! You have successfully installed Python on your CentOS 7 or 8 system.

Verifying the Python Installation

To ensure that Python is installed correctly, let’s verify it by checking its version. In your terminal, type:

python3 --version

You should see the Python version number displayed on your screen.

Setting Up Environment Variables for Python

To conveniently use Python from any location on your CentOS system, it’s recommended to set up the environment variables. Open a terminal and execute the following command:

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

This adds the Python executable to the system’s PATH, allowing you to access it globally.

Testing Python with a Simple Script

Let’s test your Python installation by running a simple script. Create a new file called using your preferred text editor and add the following code:

print("Hello, CentOS Python!")

Save the file and execute it by typing the following command in your terminal:


You should see the output Hello, CentOS Python! displayed on your screen, confirming that Python is functioning correctly.

If you’re on the hunt for Python installation instructions tailored specifically to Ubuntu, Windows, or Mac OS, you’re in luck! We’ve got separate articles dedicated to each of these operating systems. This way, you can find detailed guidance for your particular platform and make the installation process a breeze. So, feel free to explore our individual articles for Ubuntu, Windows, and Mac OS to get Python up and running on your system smoothly.

So there you have it! We’ve now reached the end of our adventure in installing Python on CentOS 7 and 8. By following the step-by-step instructions we’ve provided, you’ve successfully brought Python to life on your system. Now, armed with this powerful programming language, you can explore a vast array of possibilities. So go ahead, dive into the world of Python, and let your creativity soar. Happy coding on CentOS!

Scroll to Top