yum
先备份一下自带的yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
安装wget
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install wget
下载aliyun的yum配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
运行 makecache生成缓存
yum makecache
Python
Centos7.7 安装Python 3
系统自带Python
[root@ifeng ~]# python --version
Python 2.7.5
[root@ifeng ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
看到python在/usr/bin 目录下
为了使两个版本共存,需要
python -> python3
python2 -> python2.7
依赖关系
下载依赖包
因为要编译python3 , 首先需要下载安装的依赖包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
安装pip
#运行这个命令添加epel扩展源
yum -y install epel-release
#安装pip
yum install python-pip
pip安装wget
pip install wget
下载python
用wget下载python的压缩包
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tar.xz
编译源码包
# 解压
xz -d Python-3.6.4.tar.xz
tar -xf Python-3.6.4.tar
进入源码包
cd Python-3.6.3
./configure prefix=/usr/local/python3
make && make install
验证Python3是否安装正确
cd /usr/local/python3/bin/
./python3
配置Python3的环境变量
[root@ifeng bin]# echo "export PYTHON_HOME=/usr/local/python3" >> /etc/profile
[root@ifeng bin]# echo "export PATH=/usr/local/python3/bin:${PATH}" >> /etc/profile
切换默认python3
修改yum默认的python
#都把第一行修改为
#!/usr/bin/python2
修改默认python
回到软连接的地方
不难看出,只要把python -> python3 即可
# 删掉python
rm python
# 创建新python
ln -s python3 python