自动摘要
正在生成中……
Centos 8 没有默认安装Python,需要自己安装。
安装python3:
sudo dnf install python3
确认版本
python3 --version
注意,使用dnf或yum安装python3相关的模块需要在模块前加入python3前缀,如:
sudo dnf install python3-paramiko
安装python2:
sudo dnf install python2
确认版本
python2 --version
设置默认python版本
设置python3为系统默认版本:
sudo alternatives --set python /usr/bin/python3
设置python2为系统默认版本:
sudo alternatives --set python /usr/bin/python2
查看当前系统python的版本
python --version
alternatives 命令实际上创建了一个指向指定版本python路径的软链接,如果想移除没有进入版本化的 python:
sudo alternatives --auto python
总结
Centos8没有自带Python, 可以使用dnf install 安装特定版本的Python,使用 alternatives 可以在多个Python版本中切换。