redhat升级python到2.7.6

从今天开始学习python!看了一下虚拟机redhat中的python,发现还是原生的2.4.3,所以决定升级一下

[root@linuxidc ~]# python python 2.4.3 (#1, may 5 2011, 16:39:10)[gcc 4.1.2 20080704 (red hat 4.1.2-50)] on linux2type “help”, “copyright”, “credits” or “license” for more information.>>>[root@linuxidc ~]#

1.下载z最新版本的python

[root@linuxidc ~]# wget http://python.org/ftp/python/2.7.6/python-2.7.6.tgz

2.解压及编译

[root@linuxidc ~]# tar xvf python-2.7.2.tar.bz2[root@linuxidc python-2.7.6]# ./configure –prefix=/usr/local/python27[root@linuxidc python-2.7.6]# make[root@linuxidc python-2.7.6]# make install

[root@linuxidc python-2.7.6]# ls /usr/local/python27/ -altotal 28drwxr-xr-x 6 root root 4096 mar 21 01:01 .drwxr-xr-x 13 root root 4096 mar 21 01:01 ..drwxr-xr-x 2 root root 4096 mar 21 01:01 bindrwxr-xr-x 3 root root 4096 mar 21 01:01 includedrwxr-xr-x 4 root root 4096 mar 21 01:01 libdrwxr-xr-x 3 root root 4096 mar 21 01:01 share

3.覆盖原有的python链接

[root@linuxidc python-2.7.6]# mv /usr/bin/python /usr/bin/python_old[root@linuxidc python-2.7.6]# ln -s /usr/local/python27/bin/python /usr/bin/[root@linuxidc python-2.7.6]# pythonpython 2.7.6 (default, mar 21 2014, 01:00:09) [gcc 4.1.2 20080704 (red hat 4.1.2-44)] on linux2type “help”, “copyright”, “credits” or “license” for more information.>>>

此时已经可以正常使用python2.7了,但是因为yum是使用的2.4的版本来用的,现在输入一下yum就会报错

[root@linuxidc python-2.7.6]# yumthere was a problem importing one of the python modulesrequired to run yum. the error leading to this problem was:

no module named yum

please install a package which provides this module, orverify that the module is installed correctly.

it’s possible that the above module doesn’t match thecurrent version of python, which is:2.7.6 (default, mar 21 2014, 01:00:09) [gcc 4.1.2 20080704 (red hat 4.1.2-44)]

if you cannot solve this problem yourself, please go to the yum faq at: http://wiki.linux.duke.edu/yumfaq

5.修改yum

[root@linuxidc python-2.7.6]# vim /usr/bin/yum

#!/usr/bin/python #修改此处为2.4的位置

[root@linuxidc python-2.7.6]# vim /usr/bin/yum

#!/usr/bin/python2.4

yum 可以使用了!

[root@linuxidc python-2.7.6]# yumloaded plugins: rhnplugin, securityyou need to give some commandusage: yum [options] command

list of commands:

check-update check for available package updatesclean remove cached datadeplist list a package’s dependencieserase remove a package or packages from your systemgroupinfo display details about a package groupgroupinstall install the packages in a group on your systemgrouplist list available package groupsgroupremove remove the packages in a group from your systemhelp display a helpful usage messageinfo display details about a package or group of packagesinfo-security returns security data for the packages listed, that affects your systeminstall install a package or packages on your systemlist list a package or groups of packageslist-security returns security data for the packages listed, that affects your systemlocalinstall install a local rpmmakecache generate the metadata cacheprovides find what package provides the given valuereinstall reinstall a packagerepolist display the configured software repositoriesresolvedep determine which package provides the given dependencysearch search package details for the given stringshell run an interactive yum shellupdate update a package or packages on your systemupdate-minimal works like update, but goes to the ‘newest’ package match which fixes a problem that affects your systemupgrade update packages taking obsoletes into account

options: -h, –help show this help message and exit -t, –tolerant be tolerant of errors -c run entirely from cache, don’t update cache -c [config file] config file location -r [minutes] maximum command wait time -d [debug level] debugging output level –showduplicates show duplicates, in repos, in list/search commands -e [error level] error output level -q, –quiet quiet operation -v, –verbose verbose operation -y answer yes for all questions –version show yum version and exit –installroot=[path] set install root –enablerepo=[repo] enable one or more repositories (wildcards allowed) –disablerepo=[repo] disable one or more repositories (wildcards allowed) -x [package], –exclude=[package] exclude package(s) by name or glob –disableexcludes=[repo] disable exclude from main, for a repo or for everything –obsoletes enable obsoletes processing during updates –noplugins disable yum plugins –nogpgcheck disable gpg signature checking –disableplugin=[plugin] disable plugins by name –enableplugin=[plugin] enable plugins by name –skip-broken skip packages with depsolving problems –security include security relevant packages –cve=cve include packages needed to fix the given cve –bz=bz include packages needed to fix the given bz –advisory=advisory include packages needed to fix the given advisory[root@linuxidc python-2.7.6]#

python 的详细介绍:请点这里python 的下载地址:请点这里

推荐阅读:

《python开发技术详解》.( 周伟,宗杰).[高清pdf扫描版+随书视频+代码] http://www.linuxidc.com/linux/2013-11/92693.htm

python脚本获取linux系统信息 http://www.linuxidc.com/linux/2013-08/88531.htm

更多redhat相关信息见redhat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10