Tuesday 27 March 2018

Upgrade Python from 2.6.x to 2.7.x on RHEL/CentOS 6

Downloading latest Python version:

[root@sankar ~]# cd /opt

[root@sankar ~]#pwd
/opt
[root@sankar ~]# wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz 
--2018-03-23 16:40:12--  http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
Resolving www.python.org... 151.101.116.223, 2a04:4e42:1c::223
Connecting to www.python.org|151.101.116.223|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz [following]
--2018-03-23 16:40:12--  https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
Connecting to www.python.org|151.101.116.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10525244 (10M) [application/octet-stream]
Saving to: “Python-2.7.8.tar.xz”

100%[=========================================================================================>] 10,525,244  --.-K/s   in 0.1s    

2018-03-23 16:40:12 (95.9 MB/s) - “Python-2.7.8.tar.xz” saved [10525244/10525244]

[root@sankar ~]# ls -ltrh
total 24M
-rw-r--r--   1 root    root   9.8M May 11  2013 Python-2.7.5.tar.xz
-rw-r--r--   1 root    root    11M Jun 29  2014 Python-2.7.8.tar.xz
drwxr-xr-x   3 root    root   4.0K Aug 24  2016 sun
drwxr-xr-x   4 root    bin    4.0K Aug 24  2016 SYMCquiesce
-rw-r--r--   1 root    root   3.8M Mar  3  2017 xymon-4.3.28.tar.gz
drwxrwxr-x  16     500 nagios 4.0K Mar  3  2017 xymon-4.3.28
drwxr-xr-x   5 monitor ctsrvp 4.0K Mar 24  2017 monitor
drwx------   7 ansible ctmemp 4.0K Aug  3  2017 ansible
drwxr-xr-x.  2 root    root   4.0K Oct  3 13:05 rh
drwxr-xr-x  18 root    root   4.0K Mar 20 03:46 Python-2.7.5
[root@sankar ~]#

[root@sankar ~]#tar -xvf  Python-2.7.8.tar.xz 
[root@sankar ~]#ls -ltrh
total 24M
-rw-r--r--   1 root    root   9.8M May 11  2013 Python-2.7.5.tar.xz
drwxr-xr-x  17    1000   1000 4.0K Jun 29  2014 Python-2.7.8
-rw-r--r--   1 root    root    11M Jun 29  2014 Python-2.7.8.tar.xz
drwxr-xr-x   3 root    root   4.0K Aug 24  2016 sun
drwxr-xr-x   4 root    bin    4.0K Aug 24  2016 SYMCquiesce
-rw-r--r--   1 root    root   3.8M Mar  3  2017 xymon-4.3.28.tar.gz
drwxrwxr-x  16     500 nagios 4.0K Mar  3  2017 xymon-4.3.28
drwxr-xr-x   5 monitor ctsrvp 4.0K Mar 24  2017 monitor
drwx------   7 ansible ctmemp 4.0K Aug  3  2017 ansible
drwxr-xr-x.  2 root    root   4.0K Oct  3 13:05 rh
drwxr-xr-x  18 root    root   4.0K Mar 20 03:46 Python-2.7.5
[root@sankar ~]#

[root@sankar ~]# ./configure --prefix=/usr/local

[root@sankar ~]# make

[root@sankar ~]# make altinstall


[root@sankar ~]# python2.7 -V
Python 2.7.8
[root@sankar ~]# python2.7
Python 2.7.8 (default, Mar 23 2018, 17:50:22) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()

Now we need to create a alias from default python path to latest version
[root@sankar ~]#python -V
Python 2.6.6

[root@sankar ~]# vi ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
# User specific aliases and functions
alias python=/usr/local/bin/python2.7

[root@sankar ~]#source ~/.bashrc

Now it's shows upgraded version only
[root@sankar ~]#python -V
Python 2.7.8

No comments:

Post a Comment