下載源碼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.完成