Today, I was trying to install an application on my CentOS 7.4 system which required Python >= 2.7.10, but there are Python 2.7.5 installed, which we can’t remove as other applications depend on it. This tutorial will help you to install Python 2.7.14 without removing older versions.
Step 1 – Install GCC
Firstly make sure that you have GCC package installed on your system. Use the following command to install GCC if you don’t have it installed.
yum install gcc openssl-devel bzip2-devel
Step 2 – Download Python 2.7
Download Python using following command from python official site. You can also download the latest version in place of specified below.
cd /usr/src wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
Step 3 – Extract Archive and Compile
Use below set of commands to extract Python source code and compile it into your system using
tar xzf Python-2.7.14.tgz cd Python-2.7.14 ./configure --enable-optimizations make altinstall
Step 4 – Check Python Version
Check the latest version installed of python using below command. During this installation, the latest Python binary was installed on path /usr/local/bin/python2.7. The existing binary was located under /usr/bin.
/usr/local/bin/python2.7 -VPython 2.7.14
Step 5 – Install PIP
PIP is a useful utility to install and manage Python modules. Let’s install the PIP for the installed Python version.
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py" python2.7 get-pip.py