CentOS下自带的都是Python2系列, 如果要安装Python3.0以上,就要手动安装。下面演示安装Python3.5.
1.先安装所需要的依赖
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
2.获取下载网页并下载到本地
wget "https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz"
3.将下载的安装包解压
tar -zxvf Python-3.5.0.tgz
4.将解压后的安装包复制到/usr/local下
cp Python-3.5.0 /usr/local/
5.配置并编译
cd /usr/local/Python-3.5.0
./configure
make
make install
6.备份旧版本Python2的链接, 重新指向Python3.5
cd /usr/bin
mv python python.bak(备份前可以ls -ltr python*看看链接情况)
ln -s /usr/local/bin/python3 /usr/bin/python(将Python3链接到python)
7.检查版本号是否链接成功
python --version