The default python version of CentOS 7 is python2.7.5. Because yum depends on the default python version, you must keep the default version and modify the header of the yum file before you can start to install and update the two latest versions of python2 and python3. (python2 and python3 coexist)
1. Keep the default python version 2.7.5, and modify the yum header to keep yum's dependence on the default version python2.7.5
1.su root # Get root privileges
2.mv /usr/bin/python2.7 /usr/bin/python2.7.5 # Keep the default version python as python2.7.5
ln -s /usr/bin/python2.7.5 /usr/local/bin/python2.7.5 # Create a soft link
3.ll /usr/bin/yum* # View the headers of all yum files (7) in the /usr/bin/ directory
4.vi /usr/bin/yum* # Modify the headers of all yum files (7) 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
2. Install the latest version of python2.7.13 and python3.6.2 (python2 and python3 coexist, the default version after modification is python3.6.2)
Ready to work:
1. Install the wget command (the command that can download the installation package online)
yum -y install wget
2. Prepare the build environment
yum groupinstall 'Development Tools'
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel
3. Download and install the latest version of 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
start installation:
1. Go to the download directory:
cd /usr/local/src
2. 下载并安装最新版本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. 下载并安装最新版本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
Reprinted from: CentOS7 retains the default Python version and installs the updated Python2 and Python3 coexistence