How to Install Python 3.6 on CentOS 6

CentOS 6 has Python 2.6.6 pre-installed which can’t be upgraded. Forcefully upgrading or replacing this version causes yum and many other utilities to break.  In this tutorial we will install a new version of python using alternate install method. This will create a new python version in /usr/local.

Quick Reference:

Path
Python installation dir /usr/local/lib/python3.6
Python executable /usr/local/bin/python3.6
Pip executable /usr/local/bin/pip3.6

Step 1: System Package Installation

Install below pre-requisites:

1
sudo yum -y install gcc openssl-devel bzip2-devel

Step 2: Downloading Python

Download python

1
2
cd /tmp/
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz

Step 3: Python Alternate Installation

1
2
3
4
5
6
tar xzf Python-3.6.6.tgz
cd Python-3.6.6
./configure --enable-optimizations
sudo make altinstall

sudo ln -sfn /usr/local/bin/python3.6 /usr/bin/python3.6

Step 4: Verifying new version

1
2
python3.6 -V
Python 3.6.6

Shell Script Shortcut

Warning: Never run shell scripts downloaded from internet. Fork or download below script, review and keep your own local copy.

https://github.com/vinodpandey/scripts/blob/master/python3-centos-6.sh