How Do You Upgrade Python 2.6 to Python 2.7 on CentOS 6?

Problem scenario
On your Linux CentOS 6.x server you run "python --version" and find that Python 2.6 is installed.  You want Python 2.7 to be installed instead.  You do not want to use binaries (e.g., .rpm packages) or yum repositories. What do you do?

Solution
Run these commands:
curl -k https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz > Python-2.7.14.tar.xz
sudo mv Python-2.7.14.tar.xz /usr/bin/
cd /usr/bin/
sudo tar xf Python-2.7.14.tar.xz
cd Python-2.7.14
sudo ./configure --prefix=/usr/local
sudo make && sudo make altinstall

# You must use "altinstall" in the command above.  If you use "make install", you will have two versions of Python installed.

sudo ln -s /usr/local/bin/python2.7 /usr/local/bin/python
# Log off and log back in. You should now be done.

If you want to know how to upgrade Python from a major version (2 to 3) on a Debian/Ubuntu server where you can use binaries or remote repositories (and you do not want to use source media), see this posting.

Leave a comment

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