配置yum源
$ cat /etc/yum.repos.d/CentOS.repo
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [centos-sclo-rh] name=CentOS-6.10 - SCLo rh baseurl=http://vault.centos.org/centos/6.10/sclo/$basearch/rh/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
[centos-sclo-sclo] name=CentOS-6.10 - SCLo sclo baseurl=http://vault.centos.org/centos/6.10/sclo/$basearch/sclo/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
|
$ yum clean all && yum makecache
toolchain 会自动安装gcc 7和 gcc 8 以及依赖
1 2
| yum install devtoolset-7-toolchain yum install devtoolset-7-toolchain
|
列出所有软件
1 2 3
| $ scl --list devtoolset-7 devtoolset-8
|
切换软件环境(临时使用gcc7 版本)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| $ scl enable devtoolset-7 bash
$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --with-mpc=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC) $ exit exit $ scl enable devtoolset-8 bash $ $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --with-mpc=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
|
当前bash窗口关闭后 将退出gcc7 环境使用
查看gcc相关路径
1 2 3 4 5 6 7 8 9 10
| $ find / -name gcc |grep bin /opt/rh/devtoolset-8/root/usr/bin/gcc /opt/rh/devtoolset-7/root/usr/bin/gcc /usr/bin/gcc $ $ find / -name g++ |grep bin /opt/rh/devtoolset-8/root/usr/bin/g++ /opt/rh/devtoolset-7/root/usr/bin/g++ /usr/bin/g++
|
配置gcc优先级
1 2
| sudo update-alternatives --install /usr/bin/gcc gcc /opt/rh/devtoolset-8/root/usr/bin/gcc 10 --slave /usr/bin/g++ g++ /opt/rh/devtoolset-8/root/usr/bin/g++ sudo update-alternatives --install /usr/bin/gcc gcc /opt/rh/devtoolset-7/root/usr/bin/gcc 20 --slave /usr/bin/g++ g++ /opt/rh/devtoolset-7/root/usr/bin/g++
|
100/200为优先级,数字越大优先级越高。
如果 /usr/bin/gcc文件存在需要删除或是重命名.
1
| $ mv /usr/bin/gcc /usr/bin/gcc.backup
|
查看配置
1 2 3 4 5 6 7 8 9 10
| $ sudo update-alternatives --config gcc
There are 2 programs which provide 'gcc'.
Selection Command ----------------------------------------------- + 1 /opt/rh/devtoolset-8/root/usr/bin/gcc * 2 /opt/rh/devtoolset-7/root/usr/bin/gcc
Enter to keep the current selection[+], or type selection number:
|
删除 gcc 配置
1
| sudo update-alternatives --remove gcc /opt/rh/devtoolset-7/root/usr/bin/gcc
|