python upgrade on CentOS

18,009

Solution 1

For CentOS, you are better of using the pre-built Python version from the software collections library:

This is specifically built so as to be able to safely coexist with the system Python. The binaries are put together by Red Hat so as to provide more up to date versions of Python specifically for developers and running non system applications.

Solution 2

You can create a symbolic link to solve it:

$ /usr/bin/python -V
Python 2.6.x
$ move /usr/bin/python /usr/bin/python2.6.x
$ ln -sf /usr/local/bin/python2.7 /usr/bin/python
$ which yum
/usr/bin/yum
$ head -1 /usr/bin/yum
#!/usr/bin/python
$ sed -i -e 's|python|python2.6.x|' /usr/bin/yum
$ head -1 /usr/bin/yum
#!/usr/bin/python2.6.x

However, I found this answer is better than mine: Two versions of python on linux. how to make 2.7 the default

Solution 3

The simple way upgrade python2.6 to 2.7 on centOS: install-python-2-7-on-centos-rhel

Share:
18,009
Lin Ma
Author by

Lin Ma

Updated on June 04, 2022

Comments

  • Lin Ma
    Lin Ma almost 2 years

    Using CentOS and upgrade from Python 2.6 to Python 2.7.8, I upgraded successfully by building from source. But it seems python command (/usr/bin/python) still points to old python 2.6 version? Wondering what is the safe way to change default python command to point to python2.7 location (which is /usr/local/bin/python2.7)?

    [root@iZrj9aehttqhrnhsvyccszZ Python-2.7.8]# which python
    /usr/bin/python
    [root@iZrj9aehttqhrnhsvyccszZ Python-2.7.8]# ls -l /usr/bin/python
    -rwxr-xr-x 2 root root 4864 Aug 18 23:14 /usr/bin/python
    [root@iZrj9aehttqhrnhsvyccszZ Python-2.7.8]# uname -a
    Linux iZrj9aehttqhrnhsvyccszZ 2.6.32-573.22.1.el6.x86_64 #1 SMP Wed Mar 23 03:35:39 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    [root@iZrj9aehttqhrnhsvyccszZ Python-2.7.8]# which python2.7
    /usr/local/bin/python2.7