1.5. Python 在 RedHat Linux 上

如果您愿意安装二进制软件包,那么在 Linux 等类 UNIX 操作系统下安装 Python 非常容易。大多数流行的 Linux 发行版都提供了预构建的二进制软件包。或者,您始终可以从源代码编译。

要下载最新的 Python RPM,请访问 https://pythonlang.cn/ftp/python/ 并选择列出的最高版本号,然后选择该版本号内的 rpms/ 目录。然后下载版本号最高的 RPM。您可以使用 rpm 命令安装它,如下所示

示例 1.2. 在 RedHat Linux 9 上安装

localhost:~$ su -
Password: [enter your root password]
[root@localhost root]# wget https://pythonlang.cn/ftp/python/2.3/rpms/redhat-9/python2.3-2.3-5pydotorg.i386.rpm
Resolving python.org... done.
Connecting to python.org[194.109.137.226]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,495,111 [application/octet-stream]
...
[root@localhost root]# rpm -Uvh python2.3-2.3-5pydotorg.i386.rpm
Preparing...                ########################################### [100%]
   1:python2.3              ########################################### [100%]
[root@localhost root]# python          1
Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type "help", "copyright", "credits", or "license" for more information.
>>> [press Ctrl+D to exit]
[root@localhost root]# python2.3       2
Python 2.3 (#1, Sep 12 2003, 10:53:56)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits", or "license" for more information.
>>> [press Ctrl+D to exit]
[root@localhost root]# which python2.3 3
/usr/bin/python2.3
1 糟糕!仅输入 python 会显示旧版本的 Python,即默认安装的版本。这不是您想要的版本。
2 在撰写本文时,最新版本称为 python2.3。您可能希望更改示例脚本第一行中的路径以指向较新的版本。
3 这是您刚安装的较新版本 Python 的完整路径。在 #! 行(每个脚本的第一行)上使用此路径,以确保脚本在最新版本的 Python 下运行,并且请确保键入 python2.3 以进入交互式 shell。