centos7默认的python版本是2.7,现在想升级python3,同时保留python2.7
官网下载地址: https://www.python.org/ftp/python/
//执行 which python |xargs ls -l //可以看到指向了Python2 lrwxrwxrwx 1 root root 7 Sep 9 17:44 /usr/bin/python -> python2
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
yum -y install epel-release
yum -y install python-pip
pip install wget
用wget下载python3的源码包,或者自己先下载好,上传到服务器再安装,如果网络快可以直接安装
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tar.xz
xz -d Python-3.6.8.tar.xz tar -xf Python-3.6.8.tar
进入解压后的目录,依次执行下面命令进行手动编译
cd Python-3.6.8 ./configure prefix=/usr/local/python3 make && make install
yum -y install zlib zlib-devel
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python
python -V