在安裝編譯某些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)境再編譯,就可以順利通過。