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.15 without removing older versions.
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
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.15/Python-2.7.15.tgz
Extract downloaded archive using tar command.
tar xzf Python-2.7.14.tgz
3. Install Python 2.7
Now run the following commands to compile Python 2.7 and install on your system using
cd Python-2.7.15 ./configure --enable-optimizations make altinstall
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.15
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