1)编译安装python2.7
[root@mysql-master ~]# python -v
python 2.6.6
查看python的版本信息(之前的yum是通过yum安装的)
[root@mysql-master src]# wget https://www.python.org/ftp/python/2.7.9/python-2.7.9.tar.xz
[root@mysql-master src]# file python-2.7.9.tar.xz
python-2.7.9.tar.xz: xz compressed data
[root@mysql-master src]# xz -d python-2.7.9.tar.xz
[root@mysql-master src]# ls
debug kernels python-2.7.9.tar
[root@mysql-master src]# tar -xf python-2.7.9.tar
[root@mysql-master src]# cd python-2.7.9
[root@mysql-master python-2.7.9]# ./configure
[root@mysql-master python-2.7.9]# make && make install
[root@mysql-master python-2.7.9]# echo $?
0
[root@mysql-master python-2.7.9]# /usr/local/bin/python2.7 -v
python 2.7.9
[root@mysql-master python-2.7.9]# mv /usr/bin/python /usr/bin/python2.6
mv:是否覆盖”/usr/bin/python2.6″? yes
[root@mysql-master python-2.7.9]# ln -s /usr/local/bin/python2.7 /usr/bin/python
[root@mysql-master python-2.7.9]# python -v
python 2.7.9
2)调整yum的配置
因为yum使用会调用python的信息,避免重新安装python后,yum出现报错,编辑yum的文件:
[root@mysql-master python-2.7.9]# sed -i ‘s@#!/usr/bin/python@#!/usr/bin/python2.6@g’ /usr/bin/yum
[root@mysql-master python-2.7.9]# cat /usr/bin/yum |head
#!/usr/bin/python2.6
import sys
try:
import yum
except importerror:
print >> sys.stderr, “””\
there was a problem importing one of the python modules
required to run yum. the error leading to this problem was:
%s
[root@mysql-master python-2.7.9]# python
python 2.7.9 (default, nov 16 2016, 19:53:47)
[gcc 4.4.7 20120313 (red hat 4.4.7-16)] on linux2
type “help”, “copyright”, “credits” or “license” for more information.
>>> print “hello,world”
hello,world
到此,python2.7的基本安装也完成了。