标签:python
centOS下的Python版本一般都比较低,很多应用都需要升级python来完成。我装的centOS的默认的python版本是V2.6.3,但运行node.js需要的版本是2.5以上。
1。下载python3.3安装包:
yum install readline-devel.x86_64
wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
2。解压安装包:tar -zxvf Python-3.5.2.tgz
3。进入解压后目录:cd Python-3.5.2
4。创建安装目录: mkdir /usr/local/python3.5
5。编译安装: ./configure --prefix=/usr/local/python3.5
6。执行:make && make install
7。此时已完成新版本的安装,但由于老版本还在系统中,所以需要将原来/usr/bin/python链接改为新的连接:
a.先修改老的连接,执行:mv /usr/bin/python /usr/bin/python_bak。
b.再建立新连接:ln -s /usr/local/python3.5/bin/python3.5 /usr/bin/python
c.设置环境变量PATH=$PATH:/usr/local/python3.5/bin/
8。查询python版本,执行:python --version
Python 3.5.2
已安装成功了。
修改yum里python解析器为Python2.6
vim /usr/bin/yum #修改第一行
#!/usr/bin/python2.6
如果自定义安装的Python 3.5.2退格键和箭头无法正常使用,
yum install readline-devel.x86_64
再重新configure、make、make install,搞定!!
[root@www ~]# cat python_install.sh
#!/bin/bash yum install readline-devel.x86_64 version=2.7.9 main=2.7 cd ~ wget https://www.python.org/ftp/python/$version/Python-$version.tgz tar -zxvf Python-$version.tgz cd Python-$version mkdir /usr/local/python$version ./configure --prefix=/usr/local/python$version make && make install mv /usr/bin/python /usr/bin/python_bak ln -s /usr/local/python$version/bin/python$main /usr/bin/python PATH=$PATH:/usr/local/python$version/ python --version cd ~ rm -rf Python-$version.tgz Python-$version
标签:python
原文地址:http://butterflykiss.blog.51cto.com/3354010/1950581