CentOS 升級 gcc

CentOS 7 透過 yum 升級 gcc
頂多升級到 4.8.x

# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
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.

如果要使用到比較新的版本

1. Install CentOS SCLo RH repository:
# yum install centos-release-scl-rh

2. Install devtoolset-9 rpm package:
# yum install devtoolset-9

3. 切換到 devtoolset-9 環境變數
# scl enable devtoolset-9 bash

4. 觀察目前 gcc 版本,是否已經是 9.x.x
# gcc --version
gcc (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
Copyright (C) 2019 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.

# which gcc
/opt/rh/devtoolset-9/root/usr/bin/gcc

也可以依照不同需求安裝不同版本的 devtoolset

以上只有暫時生效,如果要下次登入時預設使用新版的gcc
# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
 

arrow
arrow
    全站熱搜

    helloworld 發表在 痞客邦 留言(0) 人氣()