centos7 python多版本切换

1 引言

由于需要对Ambari进行编译,然而编译过程中需要用到Python2.6而centos自带为Python2.7,所以需要在centos中同时安装Python2.6 和 Python2.7。借鉴Java JDK的方法进行了一定探究,步骤记录如下

2 安装编译Python2.6的包

```
yum groupinstall "Development tools" //安装devtoolset
yum install zlib-devel //安装编译Python需要的包包
yum install bzip2-devel
yum install openssl-devel
yum install ncurses-devel
yum install sqlite-devel
```

3 下载Python2.6源码并编译安装

```
wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tar.xz //下载python2.6包
tar -xf Python-2.6.9.tar.xz //解压python2.6包
cd Python-2.6.9 //切换路径
./configure //配置python源码
make && make altinstall //编译并安装,安装默认在/usr/local/bin/python2.6
```

4 配置软连接

```
mv /usr/bin/python2  /usr/bin/python2.bak
mv /usr/bin/python2-config  /usr/bin/python2-config.bak
ln -s /usr/local/bin/python2.6 /usr/bin/python2.6
ln -s /usr/local/bin/python2.6-config /usr/bin/python2.6-config
ln -s /usr/local/bin/python2 /usr/bin/python2.6
ln -s /usr/local/bin/python2-config /usr/bin/python2.6-config
```

5 修改yum配置使得其可用

```
vi /usr/bin/yum // 第一行改为#!/usr/bin/python2.7
vi /usr/libexec/urlgrabber-ext-down //第一行改为#!/usr/bin/python2.7
```

你可能感兴趣的:(Ambari,linux)