首先安装依赖包,centos里面是-devel,如果在ubuntu下安装则要改成-dev,依赖包缺一不可
sudo yum -y groupinstall "Development tools" sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
然后获取python3的安装包
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
解压文件:
tar -xvf Python-3.6.4.tgz
包安装在/usr/local/Python3
mkdir -p /usr/local/Python3
进入到文件目录
cd Python-3.6.4
配置
./configure --prefix=/usr/local/python3
编译安装
make
make install
做软链接
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
设置pip软连接
ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
测试是安装成功
python3 -V
因为yum源使用的Python2,替换为Python3以后,会导致其无法正常工作。需要修改以下信息:
修改yum配置文件:
vi /usr/bin/yum
测试yum能否正常使用
yum -y install vim