Admin-Ahead Community

Linux => General Linux => Topic started by: rahul on November 20, 2013, 01:01:15 pm

Title: A simple Bash script for a separate Python Installation
Post by: rahul on November 20, 2013, 01:01:15 pm
Hi,

At some point in time, we may find it necessary to have a 2nd installation of Python (maybe another version) on our server. We'll need to do so without it affecting the current installation, lest it causes other dependent applications to break (chiefly, yum). So here's a little script in bash which automates the installation of Python 2.7 on a server at a different location.

This was tested on CentOS-5.9 (with the default  Python version being 2.4.3)

Code: [Select]
#!/bin/bash
install_py(){

        #These packages are used for the build process.
        #More packages can be specified solely based on what modules you want this version of Python to use.

        echo -e "\nSetting up the Install Environment. This will take some time..."
        yum install zlib* zlib-devel readline-devel  openssl-devel bzip2-devel wget gcc python-dev -y
       
        # Compile and Build Python 2.7 under /opt
        cd /usr/local/src/
        wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
        tar xvfz Python-2.7.1.tgz
        cd Python-2.7.1
        ./configure --prefix=/opt/python2.7.1 --with-threads --enable-shared
        make
        make install

        # for shared libraries
        touch /etc/ld.so.conf.d/opt-python2.7.1.conf
        echo "/opt/python2.7.1/lib/" >> /etc/ld.so.conf.d/opt-python2.7.1.conf
        ldconfig

        #Soft links for easy access
        ln -sf /opt/python2.7.1/bin/python /usr/bin/python2.7
}
install_py

Run "python2.7" from the command line to verify the installation.

Until next time....