CentOS7 で提供されているGCCは「GCC 4.8.5」である
アプリケーションによってはこれ以上のバージョンが要求される場合がある。
なら別途GCCをコンパイルして用意するのが手なのだろうが、ハードルが高い。
なので、devtoolset パッケージを使って容易に 「GCC 4.9より新しいGCC」を使えるようにしてみた。
pkgs.orgを拝見すると
devtoolset | バージョン | 備考 |
devtoolset-3 | GCC version 4.9 | 終了 |
devtoolset-4 | GCC version 5 | 終了 |
devtoolset-6 | GCC version 6 | 終了 |
devtoolset-7 | GCC version 7 | |
devtoolset-8 | GCC version 8 | |
devtoolset-9 | GCC version 9 |
の対応みたい。細かいバージョン番号は省いてます。GCC以外にも c++、gfortran が用意されている
インストール先は
/opt/rh/devtoolset-{3,4,6,7,8,9}/root/usr/{bin,lib,libexec,share}
と別の場所にルート(/)を置く感じで、まるで chroot みたい。
まずは devtoolsetパッケージが含まれるリポジトリ「centos-release-scl-rh」をインストールします。
[root@centos7 ~]# yum install centos-release-scl-rh
これで /etc/yum.repos.d に新たなリポジトリが追加されます
中身はこんな感じです.
[root@centos7 ~]# cat /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
#baseurl=http://mirror.centos.org/centos/7/sclo/$basearch/rh/
mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
:
:
[root@centos7 ~]#
このリポジトリの概要は「yum repolist -v centos-sclo-rh」コマンドで得られます
CentOS/devtoolset/repository
ここでは最新のdevtoolsetをインストールしてみます(2101時点)
[root@centos7 ~]# yum install devtoolset-9
(これで gcc,g++,gfortran,make,binutilsらが同時にインストールされる)
(インストール先は [/opt/rh/devtoolset-9/] )
[root@centos7 ~]#
インストールをしてとてすぐさま devtoolset のGCCが使えるわけではなく導入手続きが必要.
方法は2つあって、1つはsclコマンドで有効にする
[illya@centos7 ~]$ scl -l # sclで使えるパッケージリスト
devtoolset-9
[illya@centos7 ~]$ scl enable devtoolset-9 "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.
[illya@centos7 ~]$
「scl enable devtoolset-9 "gcc --version"」という事でdevtoolsetのgccを起動してみたが、これはこの一回限りです.
永続的にdevtoolsetの環境下に置きたいならシェルを呼び込みます
[illya@centos7 ~]$ scl enable devtoolset-9 bash
[illya@centos7 ~]$ 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.
[illya@centos7 ~]$
これはログインシュルが bash なら 再度 bash を実行した形です.
明示的で分かりやすいのかもしれませんが、どうせなら立ち上げたshellが何もせずに devtoolset が有効になっているようにしたいなら「source」を使います
[illya@centos7 ~]$ source scl_source enable devtoolset-9
としてそのシェルをdevtoolsetで上書きさせるか、「.bashrc」に「source scl_source enable devtoolset-9」を記載するのもありかと
ここで whereis コマンドを使ってみると
[illya@centos7 ~]$ whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /opt/rh/devtoolset-9/root/usr/bin/gcc /usr/share/man/man1/gcc.1.gz
[illya@centos7 ~]$
となるので、基本はPATH環境変数の調整のみと思われる
そうなると
EnvironmentModulesにdevtoolsetを食わせればアプリと連動して使えるのでは?と
っで作ってみた
ファイル名は「devtoolset-9」で
#%Module1.0
#
set devtoolset devtoolset-9
set PCP_DIR /opt/rh/$devtoolset/root
setenv X_SCLS $devtoolset
setenv PCP_DIR $PCP_DIR
prepend-path LD_LIBRARY_PATH $PCP_DIR/usr/lib64:$PCP_DIR/usr/lib:$PCP_DIR/usr/lib64/dyninst:$PCP_DIR/usr/lib/dyninst
prepend-path PATH $PCP_DIR/usr/bin
prepend-path PKG_CONFIG_PATH $PCP_DIR/usr/lib64/pkgconfig
prepend-path INFOPATH $PCP_DIR/usr/share/info