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. There are a couple ways to do this:
This is the best way to install additional versions of Python since their updates will be maintained automatically. First, install the EPEL repo:
yum install python34*
The exact version may change depending on what version of CentOS you are running. The additional binaries will be in /usr/bin, for example:
Just download your preferred version from python.org.
tar -xvzf Python-2.7.6.tgz
And that’s all that’s to it! Now any scripts that require the alternate version should have the following shebang:
If you need to use pip to install modules for your alternate version, make sure to use the correct one: