CentOS 7 in the default installation of Python, relatively low version (2.7.5), in order to use the new version 3.x, need to upgrade older versions. Because many basic commands, packages are dependent on older versions, such as: yum. So, when you update Python, we recommended not to delete the old version (old and new versions can coexist).
First, view the current python version
[root@ansible ~]# python -V Python 2.7.5
Second, download and install the new package python
Into the python's official website (https://www.python.org), select the desired version. Here I chose the most current version Python3.7.4
Download page: https://www.python.org/downloads/
Most of the version 3.7.4: https://www.python.org/downloads/release/python-374/ ----> My system is centos 7, I downloaded the first, Gzipped source tarball. can be.
Install it as relevant:
[root@ansible soft]#yum install gcc gcc-c++ -y
[root@ansible soft]# wget https://www.python.org/downloads/release/python-374/
[root@ansible soft]# tar xvf Python-3.7.4.tgz
[root@ansible soft]# cd Python-3.7.4/
[root@ansible Python-3.6.1]# ./configure
[root@ansible Python-3.6.1]# make
[root@ansible Python-3.6.1]#make install
Third, verify
#python -V # a older version, a new version of Python 2.7.5 # python3 -V Python 3.6.1
Fourth, set as the default version 3.X
View Python path in / usr / bin below. Python can see links is python 2.7, so execution is equivalent to execute python python 2.7.
[root@ansible ~]# ls -al /usr/bin | grep python -rwxr-xr-x. 1 root root 11232 Dec 2 2016 abrt-action-analyze-python lrwxrwxrwx. 1 root root 7 May 26 2017 python -> python2 lrwxrwxrwx. 1 root root 9 May 26 2017 python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Nov 6 2016 python2.7
The original python soft link Rename:
# mv /usr/bin/python /usr/bin/python.bak
The python link to python3:
# ln -s /usr/local/bin/python3 /usr/bin/python
Fifth, configure yum
After upgrading Python, due to the default python pointing python3, yum not working, yum you need to edit the configuration file, then:
[root@ansible-admin Python-3.6.1]# yum list File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
SyntaxError: invalid syntax
Modify / usr / bin / yum and / usr / libexec / urlgrabber-ext-down, the #! / Usr / bin / python changed to #! / Usr / bin / python2.7, save out.
CentOS 7 in the default installation of Python, relatively low version (2.7.5), in order to use the new version 3.x, need to upgrade older versions. Because many basic commands, packages are dependent on older versions, such as: yum. So, when you update Python, we recommended not to delete the old version (old and new versions can coexist).
First, view the current python version
[root@ansible ~]# python -V Python 2.7.5
Second, download and install the new package python
Into the python's official website (https://www.python.org), select the desired version. Here I chose the most current version Python3.7.4
Download page: https://www.python.org/downloads/
Most of the version 3.7.4: https://www.python.org/downloads/release/python-374/ ----> My system is centos 7, I downloaded the first, Gzipped source tarball. can be.
Install it as relevant:
[root@ansible soft]#yum install gcc gcc-c++ -y
[root@ansible soft]# wget https://www.python.org/downloads/release/python-374/
[root@ansible soft]# tar xvf Python-3.7.4.tgz
[root@ansible soft]# cd Python-3.7.4/
[root@ansible Python-3.6.1]# ./configure
[root@ansible Python-3.6.1]# make
[root@ansible Python-3.6.1]#make install
Third, verify
#python -V # a older version, a new version of Python 2.7.5 # python3 -V Python 3.6.1
Fourth, set as the default version 3.X
View Python path in / usr / bin below. Python can see links is python 2.7, so execution is equivalent to execute python python 2.7.
[root@ansible ~]# ls -al /usr/bin | grep python -rwxr-xr-x. 1 root root 11232 Dec 2 2016 abrt-action-analyze-python lrwxrwxrwx. 1 root root 7 May 26 2017 python -> python2 lrwxrwxrwx. 1 root root 9 May 26 2017 python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Nov 6 2016 python2.7
The original python soft link Rename:
# mv /usr/bin/python /usr/bin/python.bak
The python link to python3:
# ln -s /usr/local/bin/python3 /usr/bin/python
Fifth, configure yum
After upgrading Python, due to the default python pointing python3, yum not working, yum you need to edit the configuration file, then:
[root@ansible-admin Python-3.6.1]# yum list File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
SyntaxError: invalid syntax
Modify / usr / bin / yum and / usr / libexec / urlgrabber-ext-down, the #! / Usr / bin / python changed to #! / Usr / bin / python2.7, save out.