Python 是功能强大程式语言, 很适合系统管理或执行自动化管理工作, 本文会示范在 RHEL, CentOS 及 Fedora 安装最新版 Python 3.6, 现时 Python 最新版本为 3.6.1
RHEL / CentOS / Fedora 安装 Python 3.5.
在安装 Python 3.6 前, 需要先安装 gcc 编译 Python, 如果已经安装了 gcc, 可以略过此步骤:
# yum install gcc
然后从 Python 官网下载 Python 的源始码, 最新版可以查看 Python 下载页面, 以下是下载目前最新版 Python 3.6.1 的连结:
# cd /usr/src
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
解压及编译 Python:
# tar xzf Python-3.6.1.tgz
# cd Python-3.6.1
# ./configure
# make altinstall
# cd Python-3.6.1
# ./configure
# make altinstall
上面编译时用了 “make altinstall”, 因为系统可能已经安装有旧版 Python, 这可以防止新版 Python 取代了旧有的 Python 档案, 新版 Python 的路径 /usr/bin/python3.6, 不会取代默认的 /usr/bin/python.
最后可以用以下指令检查 Python 的版本:
# python3.6 -V
回传结果会是:
Python 3.6.1