1. 程式人生 > >gcc centos 新版本的安裝方法

gcc centos 新版本的安裝方法

因為centos預設安裝的gcc是GCC 4.*.* 是不支援 C++11 的,所以有些新的程式或軟體要安裝就行要升級GCC,否則無法編譯通過

一、如下步驟安裝不成功(yum install devtoolset-4),基本上是因為倉庫不提供相應版本,請先執行yum search devtoolset查詢一下

gcc 4.8 安裝

01 02 03 04 05 06 07 08 09 10 11 12 13 [[email protected] ~] # curl -Lks http://www.hop5.in/yum/el6/hop5.repo > /etc/yum.repos.d/hop5.repo [[email protected] ~] # yum install gcc gcc-g++ -y [[email protected] ~] # gcc --version
gcc  (GCC) 4.8.2 20131212 (Red Hat 4.8.2-8) Copyright © 2013 Free Software Foundation, Inc. 本程式是自由軟體;請參看原始碼的版權宣告。本軟體沒有任何擔保; 包括沒有適銷性和某一專用目的下的適用性擔保。 [
[email protected]
~]
# g++ --version g++ (GCC) 4.8.2 20131212 (Red Hat 4.8.2-8) Copyright © 2013 Free Software Foundation, Inc. 本程式是自由軟體;請參看原始碼的版權宣告。本軟體沒有任何擔保; 包括沒有適銷性和某一專用目的下的適用性擔保。 [[email protected] ~] #

gcc 4.9 安裝

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [[email protected] ~] # yum install centos-release-scl -y [[email protected] ~] # yum install devtoolset-3-toolchain -y [[email protected] ~] # scl enable devtoolset-3 bash [[email protected] ~] # gcc --version gcc  (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 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.   [[email protected] ~] # g++ --version g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 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.   [[email protected] ~] # gfortran --version GNU Fortran (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6) Copyright (C) 2014 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   [[email protected] ~] #

gcc 5.2 安裝

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 [[email protected] ~] # yum install centos-release-scl -y [[email protected] ~] # yum install devtoolset-4-toolchain -y [[email protected] ~] # scl enable devtoolset-4 bash [[email protected] ~] # gcc --version gcc  (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2) Copyright (C) 2015 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.   [[email protected] ~] # g++ --version g++ (GCC) 5.2.1 20150902 (Red Hat 5.2.1-2) Copyright (C) 2015 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.   [[email protected] ~] #

二、使用新的辦法

yum -y install centos-release-scl-rh centos-release-scl

參考 https://linux.cn/article-8509-1.html?utm_source=weibo&utm_medium=weibo

三、重新指向國內的源頭

參考 https://blog.csdn.net/tao_627/article/details/77260963

四、新增源並安裝

rpm --import http://linuxsoft.cern.ch/cern/slc68/x86_64/RPM-GPG-KEY-cern \
 wget -O /etc/yum.repos.d/slc6-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo \
yum search devtoolset

參考 https://www.aliyun.com/jiaocheng/1389684.html