CentOS 6.5 升级python到版本2.7.14

环境:CentOS 6.5 64bit

CentOS 6.5 64bit 默认python版本:

[dup@localhost Downloads]$ python --version
Python 2.6.6


源码安装 python 2.7.14步骤:

1.下载python 2.7.14源码

[dup@localhost Downloads]$ wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
2.解压
[dup@localhost Downloads]$ tar zxvf Python-2.7.14.tgz
3.更改工作目录
[dup@localhost Downloads]$ cd Python-2.7.14
4.编译安装

[dup@localhost Python-2.7.14]$ ./configure
[dup@localhost Python-2.7.14]$ make
[dup@localhost Python-2.7.14]$ sudo make install
5.查看安装python版本信息

[dup@localhost Python-2.7.14]$ /usr/local/bin/python2.7 --version
Python 2.7.14

[dup@localhost Python-2.7.14]$ ll /usr/local/bin/
total 6668
-rwxrwxr-x 1 root root     101 Jan 19 00:53 2to3
-rwxrwxr-x 1 root root      99 Jan 19 00:53 idle
-rwxr-xr-x 1 root root    1461 Jan 17 18:59 libmcrypt-config
-rwxr-xr-x 1 root root  232465 Jan 17 19:04 mcrypt
lrwxrwxrwx 1 root root       6 Jan 17 19:04 mdecrypt -> mcrypt
-rwxr-xr-x 1 root root    2363 Jan 11 23:23 pcre-config
-rwxr-xr-x 1 root root   90015 Jan 11 23:23 pcregrep
-rwxr-xr-x 1 root root  181880 Jan 11 23:23 pcretest
-rwxrwxr-x 1 root root      84 Jan 19 00:53 pydoc
lrwxrwxrwx 1 root root       7 Jan 19 00:56 python -> python2
lrwxrwxrwx 1 root root       9 Jan 19 00:56 python2 -> python2.7
-rwxr-xr-x 1 root root 6273987 Jan 19 00:55 python2.7
-rwxr-xr-x 1 root root    1687 Jan 19 00:56 python2.7-config
lrwxrwxrwx 1 root root      16 Jan 19 00:56 python2-config -> python2.7-config
lrwxrwxrwx 1 root root      14 Jan 19 00:56 python-config -> python2-config
-rwxrwxr-x 1 root root   18547 Jan 19 00:53 smtpd.py
6.建立软连接,使系统默认的python指向python2.7,依次执行:
[dup@localhost Python-2.7.14]$ mv /usr/bin/python /usr/bin/python2.6.6
[dup@localhost Python-2.7.14]$ sudo ln -s /usr/local/bin/python2.7 /usr/bin/python
7.再次检查python版本
[dup@localhost Python-2.7.14]$ python --version
Python 2.7.14
目前已经是新版本。

8.解决系统 python 软链接指向 python2.7 版本后,因为yum是不兼容 python 2.7的,所以yum不能正常工作,需要指定 yum 的python版本。

[dup@localhost Python-2.7.14]$ yum
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.14 (default, Jan 19 2018, 00:52:34)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq
#vim /usr/bin/yum  
将文件头部的
#!/usr/bin/python
改成
#!/usr/bin/python2.6.6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值