how to Install Python 2.7 in Centos/RHEL 6
CentOS 6 come with Python 2.6 so when you upgrade to the latest (python 2.7) you will get 2.6 version but if you need python then you have to install it manually on some other location.
We can install it via yum repository by adding other repo to server and update core python but overwriting existing python can be big clash of your server because python is used to compile source files and many packages depends on this so if core package updates it will affect your server. Below a simple tutorial to install python 2.7 on some other location and use both default and newly install python on server where default python will use for server and 2.7 will use for your application as well.
So here we will install Python from source so we have to install their dependency packages as well.
Update server and install development tools
First of all you need to update your server to latest so that all packages will be latest and your repository also updated.
After that install development tools which require for python to be installed
yum -y update yum groupinstall -y 'development tools'
Also there is a need some more packages for python installation which will require the time of installation from source.
yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget
Install Python 2.7 from source
First you need to download source file from python site and then extract it.
wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz tar xf Python-2.7.8.tar.xz
Now we can start installation process as we already have all dependencies.
cd Python-2.7.8 ./configure --prefix=/usr/local make make altinstall
If all above commands run successful then your python2.7 are installed on your server. you can confirm it by below command.
linuxtweaks ~]# python2.7 -V Python 2.7.8
You can also check installation path of python 2.7 if it s properly placed
linuxtweaks ~]#which python2.7 /usr/local/bin/python2.7
You can create a symlink to the same directory by using below command
ln -s /usr/local/bin/python2.7 /usr/local/bin/python
NOTE : Please check for root and user “which python” if root pointing to “/usr/local/bin/python” then remove the soft link or change default path for root user.
linuxtweaks ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Now both python are on your server so you have to set python2.7 to user so update path variables. But before changing it first need to check it what’s the value is.
root@linuxtweaks ~]# which python /usr/bin/python user@linuxtweaks ~]$ which python /usr/local/bin/python
Setuptools installationPython 2.7 in Centos/RHEL 6
After installation of python you also need to install setuptools for installation of python packages on right location.
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz tar -xvf setuptools-1.4.2.tar.gz cd setuptools-1.4.2 python2.7 setup.py install
curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py | python2.7 -
pip2.7 install virtualenv
Confirm if setuptools installation for user and root
user@linuxtweaks ~1$ which pip /usr/local/bin/pip user@linuxtweaks ~1$ which pip pip 1.5.6 from /usr/local/lib/python2.7/site-packages (python 2.7) [root@linuxtweaks ~]# which pip /usr/bin/pip root@linuxtweaks ~]# /usr/bin/pip --version pip 1.3.1 from /usr/lib/python2.6/site-packages (python 2.6)
Finally completed and end of this you would have Python 2.7.8 installed on your server.
To know more about python programming please click here