下载地址:
https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
下载文件到指定目录
[root@operations ~]# cd /usr/local/
[root@operations local]# wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
--19:12:59-- https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
Resolving www.python.org... 103.245.222.223
Connecting to www.python.org|103.245.222.223|:443... connected.
ERROR: cannot verify www.python.org's certificate, issued by `/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA':
Unable to locally verify the issuer's authority.
To connect to www.python.org insecurely, use `--no-check-certificate'.
Unable to establish SSL connection.
注:建立连接失败,原因是目标网站证书不可用,使用`--no-check-certificate'进行忽略。
[root@operations local]# wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz --no-check-certificate
2. 解压文件
[root@operations local]# tar zxvf Python-2.7.10.tgz
[root@operations local]# ls |grep Python
Python-2.7.10
Python-2.7.10.tgz
3. 安装
[root@operations local]# cd Python-2.7.10
[root@operations Python-2.7.10]# ls
aclocal.m4 Demo Lib Modules pyconfig.h.in Tools
config.guess Doc LICENSE Objects Python
config.sub Grammar Mac Parser README
configure Include Makefile.pre.in PC RISCOS
configure.ac install-sh Misc PCbuild setup.py
[root@operations local]# cd Python-2.7.10
[root@operations Python-2.7.10]# ./configure --prefix=/usr/local/python2.7.10
[root@operations Python-2.7.10]# make && make install
4. 更新系统环境变量
[root@operations ~]# cd /usr/local/Python-2.7.10
[root@operations Python-2.7.10]# cd ../python2.7.10/
[root@operations python2.7.10]# ll
total 16
drwxr-xr-x 2 root root 4096 Aug 23 20:34 bin
drwxr-xr-x 3 root root 4096 Aug 23 20:34 include
drwxr-xr-x 4 root root 4096 Aug 23 20:34 lib
drwxr-xr-x 3 root root 4096 Aug 23 20:34 share
[root@operations python2.7.10]# python -V
Python 2.4.3 [目前还是2.4.3版本]
[root@operations python2.7.10]# whereis python
python: /usr/bin/python /usr/bin/python2.4 /usr/lib/python2.4 /usr/include/python2.4 /usr/share/man/man1/python.1.gz
方法1:
[root@operations python2.7.10]# mv /usr/bin/python /usr/bin/python2.4.3
在/etc/profile文件中添加以下两行
PATH=$PATH:/usr/local/python2.7.10/bin
export PATH
[root@operations python2.7.10]# . /etc/profile
[root@operations python2.7.10]# python -V
Python 2.7.10
方法2:设置软连接
[root@operations python2.7.10]# mv /usr/bin/python /usr/bin/python2.4.3
[root@operations profile.d]# ln -s /usr/local/python2.7.10/bin/python /usr/bin/python
[root@operations profile.d]# ll /usr/bin/python
lrwxrwxrwx 1 root root 34 Aug 23 20:43 /usr/bin/python -> /usr/local/python2.7.10/bin/python
[root@operations profile.d]# python -V
Python 2.7.10