Automatically upgrade CentOS Python to the latest official version

Source: Internet
Author: User

1#!/bin/Bash2 3#1, check the current system Python version4 5python_old_version=$ (python-v2>&1|awk '{print $}')6 Echo "the current system Python version is: $python _old_version"7 8#2, check the current system network connection, and be able to access the Python mirror site9 TenCurl-s-k-i http://mirrors.sohu.com/python/|grep ' OK ' >/dev/null One if[ $? !=0 ] A  Then -         EchoUnable to access Python mirror site, check your network connection -Exit1 the fi -  -#3, get the latest version of Python's official information -  +python_last_27version=$ (Curl-s-K http://mirrors.sohu.com/python/|awk-f '/|> ' {print $} ' |grep ' ^2.7.* ' |sort-t '. '-k3-n |tail-1 ' - Echo "The official latest Python2.7 version is: $python _last_27version" +  A#4, compare the current system Python version with the official latest version number at  - if[$python _old_version =$python _last_27version] -  Then -         Echo 'currently the latest version, no upgrade required' -Exit0 - fi in  -#5, download the latest version of the Python installation package to  + Yum Install-YwgetReadLine readline-devel - mkdir-p/tmp/Python_tmp_dir the wget-p/tmp/python_tmp_dir/http://mirrors.sohu.com/python/$python _last_27version/python-$python _last_27version.tar.xz *  $#6, unzip the python source packagePanax Notoginseng  - Tarxf/tmp/python_tmp_dir/python-$python _last_27version.Tar. xz-c/tmp/python_tmp_dir/ the  +#7, pre-compilation preparation: Preparing the installation directory A  the mkdir-p/usr/local/python27 +cd/tmp/python_tmp_dir/python-$python _last_27version -./configure--prefix=/usr/local/python27 $  $#8, compiling and installing Python -  -  Make-j$ (Cat/proc/cpuinfo |grepProcessor |WC-L) && Make Install the  -#9, upgrade Python to the latest official versionWuyi  the MV/usr/bin/python/usr/bin/python$python_old_version - LN-s/usr/local/python27/bin/python/usr/bin/python Wu  -#Ten, clean up files that are generated during installation About  $ RM-rf/tmp/python_tmp_dir/ -  -# One, upgrading only Python by default will cause Yum to not be available and fix the problem automatically here -  A sed-I.'[email protected]#!/usr/bin/[email protected]#!/usr/bin/python'$python _old_version'@'/usr/bin/Yum + sed-I.'[email protected]#!/usr/bin/[email protected]#!/usr/bin/python'$python _old_version'@'/usr/libexec/urlgrabber-ext-down &>/dev/NULL the Yum--version &>/dev/NULL&&Echo "Python Upgrade has no effect on YUM"||Echo "Python upgrade causes YUM to not work"

Automatically upgrade CentOS Python to the latest official version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.