rhel7如何通過rpm包的方式升級python


測試環境為centos7.2
因某些需要需要把系統的python版本從2.7.5升級到3.6.2,升級方式選擇rpm包的方式
注意:python的升級不需要把原本的python卸載,也一定不要卸載,否則會給系統帶來嚴重的問題

1.下載rpm包,通過http://rpm.pbone.net/,搜索相應的包,因為網站屬於外國站點,訪問速度會比較慢,稍等片刻就行,下面我提供了搜索后提取的下載鏈接
wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.4.1708/sclo/x86_64/rh/rh-python36/rh-python36-python-3.6.2-3.el7.x86_64.rpm
----------------------------------------------------------------------
2.rpm -ivh rh-python36-python-3.6.2-3.el7.x86_64.rpm
提示安裝依賴包
----------------------------------------------------------------------
3.根據提示下載相關的依賴包
wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.4.1708/sclo/x86_64/rh/rh-python36/rh-python36-runtime-2.0-1.el7.x86_64.rpm
wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.4.1708/sclo/x86_64/rh/rh-python36/rh-python36-python-libs-3.6.2-3.el7.x86_64.rpm
wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.4.1708/sclo/x86_64/rh/rh-python36/rh-python36-python-pip-9.0.1-2.el7.noarch.rpm
wget ftp://mirror.switch.ch/pool/4/mirror/centos/7.4.1708/sclo/x86_64/rh/rh-python36/rh-python36-python-setuptools-36.5.0-1.el7.noarch.rpm


[root@localhost ~]# ls   
rh-python36-python-3.6.2-3.el7.x86_64.rpm  
rh-python36-python-libs-3.6.2-3.el7.x86_64.rpm  
rh-python36-python-pip-9.0.1-2.el7.noarch.rpm  
rh-python36-python-setuptools-36.5.0-1.el7.noarch.rpm  
rh-python36-runtime-2.0-1.el7.x86_64.rpm  
-----------------------------------------------------------------
4.rpm -ivh rh*
[root@localhost ~]# rpm -ivh rh*  
警告:rh-python36-python-3.6.2-3.el7.x86_64.rpm: 頭V4 RSA/SHA1 Signature, 密鑰 ID f2ee9d55: NOKEY  
准備中...                          ################################# [100%]  
正在升級/安裝...  
   1:rh-python36-runtime-2.0-1.el7    ################################# [ 20%]  
   2:rh-python36-python-libs-3.6.2-3.e################################# [ 40%]  
   3:rh-python36-python-pip-9.0.1-2.el################################# [ 60%]  
   4:rh-python36-python-setuptools-36.################################# [ 80%]  
   5:rh-python36-python-3.6.2-3.el7   ################################# [100%]  
[root@localhost ~]# python  
Python 2.7.5 (default, Aug  4 2017, 00:39:18)   
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2  
Type "help", "copyright", "credits" or "license" for more information.  
>>> 
版本沒有變是因為沒有設置環境變量
----------------------------------------------------------------------
5.提示安裝成功后,默認安裝到opt目錄下
如果找不到可以使用find查找
-----------------------------------------------------------------------
6.cat /opt/rh/rh-python36/enable          //環境變量文件,source這個文件會立馬生效,如果需要永久生效需要寫入到profile文件中。


export PATH=/opt/rh/rh-python36/root/usr/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/opt/rh/rh-python36/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export MANPATH=/opt/rh/rh-python36/root/usr/share/man:$MANPATH
export PKG_CONFIG_PATH=/opt/rh/rh-python36/root/usr/lib64/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
export XDG_DATA_DIRS="/opt/rh/rh-python36/root/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
選中復制
---------------------------------------------------------------------
7.vi /etc/profile


將上方的復制到該文件中,保存退出
8.source /etc/profile
測試:
[root@localhost rh-python36]# python --version
Python 3.6.2


升級成功!!!




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM