How to install Python 3 from Source on CentOS 7



Many times we end up with machine having older version of Python, especially CentOS. In this quick tutorial, we will see how to install python from source. We are installing the latest Python version 3.8.3 here. But you can apply these steps for any version. Just make sure to update source link accordingly.

Installation Steps

Update system and install basic development environment

yum update -y
yum groupinstall -y 'Development Tools'
yum install -y wget zlib-devel

Grab Python tarball of version your required.


Extract tarball and go to root directory

tar -xf Python-3.8.3.tar.xz
cd Python-3.8.3

Configure the source. Here we are specifying two switches.
–prefix Determines where to keep installation files
–enabled-shared To make share shared libraries are build for this version

./configure --prefix=/usr/local --enable-shared

Time to build the source. Execute below commands


Install the source. IMPORTANT: Don’t use ‘install‘ but use ‘altinstall. This will take care of not messing existing Python installation.

make altinstall

Because we used flag ‘–enabled-shared‘, we have to add links to newly created shared libraries. To do this, first find the location of newly generated shared library. (Replace 3.8.3 with your version)

find / -name

You will get list of multiple files. Something like below.


First file is where my source is. We are not using it. Second file is what we looking for.

Now open /etc/ in your favourite editor and append the path of directory of above file to it. Below is my /etc/ after appending directory name.

include /etc/*.conf

Save and exit. Then run below command to create link.


Done ! Now try to access python.


If it works, we are good. Now let’s setup pip for this installation. First grab ‘’ script.

curl -o

Run this script using python executable we setup just now.


Check if pip is installed properly

pip3 --version

Now we are all set. Whenever you want to install pip package, make sure to specify exact pip version. Something like below.

pip3 install poetry


In case you face errors in building/compilation, and want to start again from scratch, make sure to clean source using below commands.

make clean
make distclean

Hope this helps you. Stay Awesome !

Leave a Reply