同一个系统安装多个 python 版本,不影响系统自带版本。
# 安装 Python 2.7.10
wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
tar xzvf Python-2.7.10.tgz
mkdir /usr/local/python27
cd Python-2.7.10
./configure --prefix=/usr/local/python27
make
make install
ln -s /usr/local/python27/bin/python /usr/bin/python27
# 安装 Python 3.5.0
# 3.5.0 默认会安装 pip 工具,因为其它两个版本也安装了 pip ,所以需要添加软链接区分各个版本的 pip
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz
tar xzvf Python-3.5.0.tgz
mkdir /usr/local/python35
cd Python-3.5.0
./configure --prefix=/usr/local/python35
make
make install
ln -s /usr/local/python35/bin/python3.5 /usr/bin/python35
ln -s /usr/local/python35/bin/pip3.5 /usr/bin/pip35
# 默认 python 进入自带版本,python27 进入自定义版本
[root@payun ~]# python
Python 2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@payun ~]#
[root@payun ~]# python27
Python 2.7.10 (default, Oct 4 2015, 17:50:54)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@payun ~]# python35
Python 3.5.0 (default, Oct 6 2015, 10:17:03)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>