Thursday, May 15, 2014

Installing Python 2.7 via YUM without breaking anything else on (redhat or centos)


I have searched a lot and somehow most of the places, its suggested that you install python using a python27 code base. For a new linux user this is a big task to get python build working with all the dependencies.

Before starting I want to state that I have no relation with the repository owners whose yum repo I am advising to use. It just helped me get things sorted out fast.

So first thing to install any package using yum, you will need your system to configure the yum repository.
Following steps demonstrates how to add the repository. Here we will use repository from PUIAS computational.
To add a yum repo or install a package using YUM you have to a root user

To become a root user in terminal run the following command

sudo su -
 

then to add a reposiroty to your system

cd /etc/yum.repos.d/

create a new file here with name puias.repo

vi puias.repo 

Add following content to the file

[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias


save and exit the file

If you want to disable gpgcheck you can set value to 0 in above file.

To have gpg file installed run following commands

cd /etc/pki/rpm-gpg/
wget -q http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
rpm --import RPM-GPG-KEY-puias

Now to install python packages

yum install python27 python27-tools python27-setuptools python27-devel

There you go, you have installed python27 installed in /usr/bin
If you want to make python27 default on your system then following steps will help

rm /usr/bin/python
ln -s  /usr/bin/python2.7 /usr/bin/python

Doing this above operation will break yum installation with error saying no module named yum.

I did not do enough research on installing yum module but I just changed the python interpreter in
/usr/bin/yum

vi /usr/bin/yum

Changed the first line from /usr/bin/python to /usr/bin/python2.6

Now your system should work fine.