下载源码tar包
下载地址:https://www.python.org/downloads/
我这里下载的 Python-2.7.11.tgz
# tar -zxvf Python-2.7.11.tgz
进入解压缩后的文件夹
# cd Python-2.7.11
在编译前先在/usr/local建一个文件夹python2(作为python的安装路径,以免覆盖老的版本)
# mkdir /usr/local/python2
开始编译安装
# ./configure --prefix=/usr/local/python2
# make
# make install
移动之前的版本
# mv /usr/bin/python /usr/bin/python_old
再建立新版本python的链接
ln -s /usr/local/python2/bin/python /usr/bin/python
这个时候输入
# python
Python 2.7.11 (default, Feb 19 2016, 18:01:00)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
完成
由于安装了新版的Python对yum 使用受到影响,情况如下
# yum grouplist
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.11 (default, Feb 19 2016, 18:01:00)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
意思是python版本不匹配,我们修改yum为老版本python就是了
查看原python位置
# whereis python
python: /usr/bin/python2.7 /usr/bin/python /usr/lib/python2.7 /usr/lib64/python2.7 /usr/include/python2.7 /usr/share/man/man1/python.1.gz
# vim /usr/bin/yum
修改第一行 #!/usr/bin/python
为 #!
/usr/bin/python2
.7
ok.完成