How to Upgrade Python on CentOS

How to Upgrade Python on CentOS
3.33 (66.67%) 3 votes

If you’re running CentOS, you’re probably a few versions behind on Python.  Currently, the version packaged for CentOS 5 and 6 is 2.6.  Contrary to what the title of this post implies, you actually cannot safely upgrade Python on any Redhat distribution.  If you’re feeling brave, try this to see why:

yum remove python

Warning, do not pass a ‘-y’ to the above command.  All you’re doing here is viewing output.  Hit CTRL+C once it prompts to continue, and no changes will be made to your system.

If you ran the command above, you’ll see all the packages that depend on Python, most all of which will break (including Yum itself) if you alter the system-installed package or attempt to upgrade.  Therefore, if you need a newer version of Python, the only safe way to do this is to install it alongside the system version.

This example is for installing Python 2.7, but you can easily do similar steps for version 3.3, etc.  Just download your preferred version from python.org.

cd /usr/src

wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tgz

tar -xvzf Python-2.7.6.tgz

cd Python-2.7.6

./configure –prefix=/usr/local

make

make install

 

And that’s all that’s to it!  Now any scripts that require the alternate version should have the following shebang:

#!/usr/local/bin/python2.7

 

If you need to use pip to install modules for your alternate version, make sure to use the correct one:

/usr/local/bin/pip2.7

 

Don't be selfish, share!Tweet about this on TwitterShare on RedditShare on TumblrBuffer this pageDigg thisShare on FacebookFlattr the authorEmail this to someoneShare on Google+Pin on PinterestPrint this pageShare on LinkedInShare on StumbleUpon

5 Comments

  1. Kenny Reply

    First off excellent article.

    One minor issue:

    ./configure –prefix=/usr/local

    looks like it is a single hyphen, when it should be a double hyphen! #fontproblems

    lol, just thought I would point that out in case any newbies had some trouble.

  2. Anonymous Reply

    I got distracted when i first came to your website, but then went back to it. Somehow i closed over the most important part of your wording. I ran the “yum remove python” and now 70+ low traffic websites are offline. I’ve never made a mistake this bad in my 17 years a system admin. How can i be so stupid?

    I’m having a bad day. Good news is, this gives me a reason to upgrade to CentOS 6.x rather than being stuck on on CentOS 5.8.

  3. J Davis Reply

    In your post you wrote:

    [code] ./configure –prefix=/usr/local [/code]

    THat’s a hypehn not a minus sign and it should be a double minus sign.

    [code] ./configure --prefix=/usr/local [/code]

  4. Pingback: Cassandra Basics | Site Title

Leave a Reply

Your email address will not be published. Required fields are marked *

Log in