CentOS 7.3にGCC 11をインストール (SCL)

概要

scl を用いて古い CentOS (7.3)に,新しい GCC (11)をインストールする方法を説明します.

SCL

Rehhat scl (SOFTWARE COLLECTIONS)を用いれば,yumの標準パッケージより新しいバージョンのソフトウェアをインストールできます.

インストール方法

sclのインストール

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

sclで提供されている GCC のバージョンの確認

yum list | grep devtoolset | grep gcc

devtoolset-10-gcc.x86_64 10.2.1-11.2.el7 @centos-sclo-rh
devtoolset-10-gcc-c++.x86_64 10.2.1-11.2.el7 @centos-sclo-rh
devtoolset-11-gcc.x86_64 11.2.1-1.2.el7 @centos-sclo-rh
devtoolset-11-gcc-c++.x86_64 11.2.1-1.2.el7 @centos-sclo-rh
devtoolset-10-gcc-gdb-plugin.x86_64 10.2.1-11.2.el7 centos-sclo-rh
(略)
devtoolset-10-libgccjit-docs.x86_64 10.2.1-11.2.el7 centos-sclo-rh
devtoolset-11-annobin-plugin-gcc.x86_64 9.82-1.el7.1 centos-sclo-rh
devtoolset-11-gcc-gdb-plugin.x86_64 11.2.1-1.2.el7 centos-sclo-rh
devtoolset-11-gcc-gfortran.x86_64 11.2.1-1.2.el7 centos-sclo-rh
devtoolset-11-gcc-plugin-devel.x86_64 11.2.1-1.2.el7 centos-sclo-rh
devtoolset-11-libgccjit.x86_64 11.2.1-1.2.el7 centos-sclo-rh
devtoolset-11-libgccjit-devel.x86_64 11.2.1-1.2.el7 centos-sclo-rh
devtoolset-11-libgccjit-docs.x86_64 11.2.1-1.2.el7 centos-sclo-rh
devtoolset-7-gcc.x86_64 7.3.1-5.16.el7 centos-sclo-rh
(略)
devtoolset-9-libgccjit-docs.x86_64 9.3.1-2.2.el7 centos-sclo-rh

"yum list | grep devtoolset | grep gcc"の結果

gcc 7から11が提供されていることが分かります.

GCC 11のインストール

yum install -y devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils

GCC 11が有効な状態でbashを起動

scl enable devtoolset-11 bash
gcc --version

gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
Copyright (C) 2021 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.

"gcc --version"の結果

上記の様に,「GCC 11が有効なbash」の上では,GCC 11が使えます.

動作確認

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

$ scl enable devtoolset-11 bash
$ gcc --version
gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
Copyright (C) 2021 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.

$ exit
exit
$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
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.

$ scl enable devtoolset-11 "gcc --version"
gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)
Copyright (C) 2021 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.

通常のshell (bash)の上で gcc を起動すると,gcc 4.8.5 が起動します.
「GCC 11が有効なbash」の上で gcc を起動すると,gcc 11.2.1 が起動します.
「GCC 11が有効なbash」をexitで終了して,
再度 通常のshell (bash)の上で gcc を起動すると,gcc 4.8.5 が起動します.
「GCC 11が有効な状態」で gcc を起動すると,やはり gcc 11.2.1 が起動します.


この記事が気に入ったらサポートをしてみませんか?