CentOS6.5下(不升級系統(tǒng)和內(nèi)核) 搭建Python2.7 + gcc4.8編譯環(huán)境

在安裝編譯某些node模塊時,需要Python2.7和gcc4.8編譯環(huán)境,為了不影響別的代碼程序,需要在不更新的情況下搭建環(huán)境,步驟如下。
注:不可運行 sudo yum update,會將系統(tǒng)升級。

1.安裝SCL軟件集

scl是一個第三方軟件源,軟件支持很豐富。那么通過它安裝的軟件,不會影響系統(tǒng)原來的軟件和配置,每次使用時,只需要用命令切換一下。

安裝命令sudo yum install centos-release-scl
切換命令scl enable <scl-package> <command>
注:enable 激活后只在當前terminal下有用,其他情況均為系統(tǒng)默認環(huán)境

2.安裝Python2.7

  • 安裝python2.7
    sudo yum install python27
  • 通過scl切換至此版本
    scl enable python27 bash
  • 安裝Python2.7的pip
    cd /opt/rh/python27/root/usr/bin/ # cd to the directory where SCL installs python
    sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./easy_install-2.7 pip
    sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH ./pip2.7 install requests
  • 驗證安裝
    python --version
    Python 2.7.8

3.升級gcc至4.8

  • 查看系統(tǒng)版本
    $ cat /etc/centos-release CentOS release 6.5 (Final)
  • 導(dǎo)入CERN's GPG key
    sudo rpm --import http://ftp.scientificlinux.org/linux/scientific/5x/x86_64/RPM-GPG-KEYs/RPM-GPG-KEY-cern
  • 將庫信息保存為/etc/yum.repos.d/slc6-devtoolset.repo
    wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
  • 進行安裝
    sudo yum install devtoolset-2
  • 使用scl切換至4.8版本
    scl enable devtoolset-2 bash
  • 驗證安裝
    gcc --version gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    gfortran --version GNU Fortran (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15) Copyright (C) 2013 Free Software Foundation, Inc. GNU Fortran comes with NO WARRANTY, to the extent permitted by law. You may redistribute copies of GNU Fortran under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING

至此,通過scl enable命令切換至需要的環(huán)境再編譯,就可以順利通過。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容