Install Python 2.5 or 2.6 on CentOS

Installing Python 2.5 or 2.6 on CentOS can be a bit tricky due to the outdated python 2.4 package that comes pre-installed. However, with the right steps, you can easily install and configure Python 2.5 or 2.6 on your CentOS system.

Step 1: Install a New Repository
To start, we need to add a new repository that will provide us with the latest versions of Python. We’ll use the GeekyMedia repository, which is a popular source for Linux packages.

Open a terminal and run the following command:

wget --directory-prefix=/etc/yum.repos.d/ http://mirrors.geekymedia.com/centos/geekymedia.repo

This will download the repository configuration file and save it to the /etc/yum.repos.d/ directory.

Step 2: Install Python 2.5 or 2.6
Now that we have the new repository installed, we can proceed with installing Python 2.5 or 2.6 using yum.

yum -y install python25

This will install Python 2.5. You can also install Python 2.6 by running:

yum -y install python26

Step 3: Update the Python Path
After installing Python, we need to update the path so that our system uses the new version of Python instead of the old 2.4 package.

  1. Rename the existing /usr/bin/python file to /usr/bin/python.old.
mv /usr/bin/python /usr/bin/python.old

This will ensure that any changes we make in the next step won’t affect the original Python installation.

  1. Create a symbolic link to point to the new version of Python.
    For Python 2.5, run:
ln -s /usr/bin/python25 python

For Python 2.6, run:

ln -s /usr/bin/python26 python

This will create a symbolic link that our system will use when we run python.

Testing the Installation
To verify that our installation was successful, simply run the following command:

python

You should see the version of Python that you installed earlier.

Python 2.5.1 (r251:54863, Sep 24 2008, 16:12:26)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Note: The output may vary depending on the version of Python you installed and the system configuration.