The default Python version of CentOS 7 is python2.7.5. Because Yum relies on the default Python version, it is necessary to keep the default version and modify the Yum file header before you can start installing Update Python2 and Python3 two latest versions. (Coexistence of Python2 and Python3)
One. Keep the default Python version 2.7.5, and modify the Yum header to keep yum dependent on the default version python2.7.5
1.su root # get root permissions
2.mv/usr/bin/python2.7/usr/bin/python2.7.5 # Keep the default version of Python for python2.7.5
Ln-s/usr/bin/python2.7.5/usr/local/bin/python2.7.5 # Creating a soft connection
3.ll/usr/bin/yum* # View all yum files (7) heads in the/usr/bin/directory
4.vi/usr/bin/yum* # Modify all yum files (7) headers in the/usr/bin/directory
#!/usr/bin/python-> #!/usr/bin/python2.7.5
5.vi/usr/libexec/urlgrabber-ext-down # Modify the Urlgrabber-ext-down header in the/usr/libexec/directory
#!/usr/bin/python-> #!/usr/bin/python2.7.5
Two. Install the latest version of python2.7.13 and python3.6.2 (Python2 and Python3 coexistence, the default version is python3.6.2 after modification)
Preparatory work:
1. Install the wget command (the command to download the installation package online)
Yum-y Install wget
2. Preparing the compilation environment
Yum Groupinstall ' Development Tools '
Yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
3. Download and install the latest version of the Python2 and Python3 tgz compressed files
Https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
Https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
To start the installation:
1. Go to the download directory:
Cd/usr/local/src
2. Download and install the latest version Python2:
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
Tar zxvf python-2.7.13.tgz
CD Python-2.7.13
./configure
Make all
Make install
Make clean
Make Distclean
Rm-rf/usr/bin/python
Rm-rf/usr/bin/python2
rm-rf/usr/bin/python2.7
Ln-s/usr/local/bin/python2.7/usr/bin/python
Ln-s/usr/local/bin/python2.7/usr/bin/python2
Ln-s/usr/local/bin/python2.7/usr/bin/python2.7
/usr/bin/python-v
/usr/bin/python2-v
/usr/bin/python2.7-v
Rm-rf/usr/local/bin/python
Rm-rf/usr/local/bin/python2
Ln-s/usr/local/bin/python2.7/usr/local/bin/python
Ln-s/usr/local/bin/python2.7/usr/local/bin/python2
Python-v
Python2-v
Python2.7-v
3. Download and install the latest version Python3:
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
Tar zxvf python-3.6.2.tgz
CD Python-3.6.2
./configure
Make all
Make install
Make clean
Make Distclean
Rm-rf/usr/bin/python
Rm-rf/usr/bin/python3
rm-rf/usr/bin/python3.6
Ln-s/usr/local/bin/python3.6/usr/bin/python
Ln-s/usr/local/bin/python3.6/usr/bin/python3
Ln-s/usr/local/bin/python3.6/usr/bin/python3.6
/usr/bin/python-v
/usr/bin/python3-v
/usr/bin/python3.6-v
Rm-rf/usr/local/bin/python
Rm-rf/usr/local/bin/python3
Ln-s/usr/local/bin/python3.6/usr/local/bin/python
Ln-s/usr/local/bin/python3.6/usr/local/bin/python3
Python-v
Python3-v
Python3.6-v
Python version and install update Python2 and Python3 two latest versions (Python2 and Python3 coexistence)