要在 CentOS 上更新 Python,您需要遵循以下步骤:
首先,打开终端。
检查当前安装的 Python 版本。在终端中输入以下命令:
python --version
或者,如果您使用的是 Python 3,请输入:
python3 --version
sudo yum update
sudo yum install epel-release
sudo yum install centos-release-scl
sudo yum install rh-python38
这将安装 Python 3.8。您可以根据需要替换版本号。
scl enable rh-python38 bash
这将启动一个新的 bash shell,其中包含新安装的 Python 版本。
python --version
或者,如果您使用的是 Python 3,请输入:
python3 --version
现在,您应该看到已更新的 Python 版本。
请注意,这些步骤适用于 CentOS 7。如果您使用的是 CentOS 8,Python 3 已经是默认安装的,并且通常会自动更新。要更新 Python 3,只需运行 sudo dnf update python3
。