分类目录归档:Programming

Linux升级Python步骤

首先在官网下载要更新安装的Python包,下载地址https://www.python.org/downloads
Python下载完成后上传到服务器,然后解压进行编译安装:
[root@monitor ~]# pwd
/root
[root@monitor ~]# tar -xzvf Python-2.7.10.tgz
[root@monitor ~]# cd Python-2.7.10
[root@monitor Python-2.7.10]# pwd
/root/Python-2.7.10
解压后可以查看README帮助文档进行安装,默认安装在/usr/local目录下:
[root@monitor Python-2.7.10]# ./configure
[root@monitor Python-2.7.10]# make
[root@monitor Python-2.7.10]# make install
[root@monitor Python-2.7.10]# cd /usr/local/bin/
[root@mysql ~]# cd /usr/local/bin/
[root@mysql bin]# ls -l
total 6116
-rwxr-xr-x. 1 root root     101 Aug 14 09:56 2to3
-rwxr-xr-x. 1 root root      99 Aug 14 09:56 idle
-rwxr-xr-x. 1 root root      84 Aug 14 09:56 pydoc
lrwxrwxrwx. 1 root root       7 Aug 14 09:59 python -> python2
lrwxrwxrwx. 1 root root       9 Aug 14 09:59 python2 -> python2.7
-rwxr-xr-x. 1 root root 6225046 Aug 14 09:58 python2.7
-rwxr-xr-x. 1 root root    1687 Aug 14 09:59 python2.7-config
lrwxrwxrwx. 1 root root      16 Aug 14 09:59 python2-config -> python2.7-config
lrwxrwxrwx. 1 root root      14 Aug 14 09:59 python-config -> python2-config
-rwxr-xr-x. 1 root root   18547 Aug 14 09:56 smtpd.py
此时没有覆盖老版本:
[root@mysql ~]# python
Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
[root@mysql ~]# which python
/usr/local/bin/python
[root@mysql ~]# whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7-config /usr/local/bin/python2.7 /usr/local/bin/python /usr/local/lib/python2.7 /usr/include/python2.6 /usr/share/man/man1/python.1.gz 
将原来/usr/bin/python链接重命名:
[root@mysql ~]# mv /usr/bin/python /usr/bin/python_old
再建立新版本Python的链接
ln -s /usr/local/bin/python2.7  /usr/bin/python
这个时候输入python就会显示出python的新版本信息:
[root@mysql bin]# python
Python 2.7.10 (default, Aug 14 2016, 09:56:11)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
注意从Python3版本开始,默认安装可能会覆盖Linux下自带的老版本Python,也有可能不覆盖,具体看安装过程。