一,下载python版本
//下载python2.7.11版本
[root@miao ~]# wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
[root@miao ~]# ll
总用量 744
-rw-r--r-- 1 root root 753936 2月 11 10:15 Python-2.7.11.tgz
二,解包 配置 编译 安装
//解压
[root@miao ~]# tar xf Python-2.7.11.tgz -C /usr/src/
[root@miao ~]# cd /usr/src/Python-2.7.11
//创建编译路径
[root@miao Python-2.7.11]# mkdir /usr/local/python27
//配置编译安装
[root@miao Python-2.7.11]# ./configure --prefix=/usr/local/python27 && make && make install
三,查看版本,并启动python
//此时还是原来的旧版本,不要卸载
[root@miao Python-2.7.11]# python -V
Python 2.7.5
//查询位置
[root@miao Python-2.7.11]# which python
/usr/bin/python
//重命名为旧的
[root@miao Python-2.7.11]# mv /usr/bin/python /usr/bin/python_old
//做软连接
[root@miao Python-2.7.11]# ln -s /usr/local/python27/bin/python /usr/bin
[root@miao Python-2.7.11]# ll /usr/bin/python
lrwxrwxrwx 1 root root 30 2月 11 11:31 /usr/bin/python -> /usr/local/python27/bin/python
//查看已为安装的新版本
[root@miao Python-2.7.11]# python -V
Python 2.7.11
做完软连接后可以直接python进入交互模式。
//当yum不能用时:
[root@miao Python-2.7.11]# which yum
/usr/bin/yum
[root@miao Python-2.7.11]# vim /usr/bin/yum
#!/usr/bin/python_old 后面加上_old就可以用了
四,也可以bin下启动python
//进入编译路径 查看 bin目录下启动
[root@miao ~]# cd /usr/local/python27/
[root@miao python27]# ll
总用量 20
drwxr-xr-x 2 root root 4096 2月 11 11:22 bin
drwxr-xr-x 3 root root 4096 2月 11 11:22 include
drwxr-xr-x 4 root root 4096 2月 11 11:22 lib
drwxr-xr-x 6 mysql mysql 4096 12月 6 2015 Python-2.7.11
drwxr-xr-x 3 root root 4096 2月 11 11:22 share
[root@miao python27]# cd bin
[root@miao bin]# ll
总用量 8092
-rwxr-xr-x 1 root root 110 2月 11 11:22 2to3
-rwxr-xr-x 1 root root 108 2月 11 11:22 idle
-rwxr-xr-x 1 root root 93 2月 11 11:22 pydoc
lrwxrwxrwx 1 root root 7 2月 11 11:22 python -> python2
lrwxrwxrwx 1 root root 9 2月 11 11:22 python2 -> python2.7
-rwxr-xr-x 1 root root 8248792 2月 11 11:22 python2.7
-rwxr-xr-x 1 root root 1696 2月 11 11:22 python2.7-config
lrwxrwxrwx 1 root root 16 2月 11 11:22 python2-config -> python2.7-config
lrwxrwxrwx 1 root root 14 2月 11 11:22 python-config -> python2-config
-rwxr-xr-x 1 root root 18556 2月 11 11:22 smtpd.py
[root@miao bin]# ./python2
Python 2.7.11 (default, Feb 11 2022, 11:22:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit() //退出交互模式