(SCL)源出现了,以帮助解决 RHEL/CentOS 下的这种问题。SCL 的创建就是为了给 RHEL/CentOS 用户提供一种以方便、安全地安装和使用应用程序和运行时环境的多个(而且可能是更新的)版本的方式,同时避免把系统搞乱。与之相对的是第三方源,它们可能会在已安装的包之间引起冲突。 关于 Software Collections RedHat 官方是这样介绍的:
For certain applications, more recent versions of some software components are often needed in order to use their latest new features. Red Hat Software Collections is a Red Hat offering that provides a set of dynamic programming languages, database servers, and various related packages that are either more recent than their equivalent versions included in the base Red Hat Enterprise Linux system, or are available for this system for the first time.
RedHat 推出 Software Collections 的目的就是为了解决前面说的问题,想在 RedHat 系统下能使用新版本的工具,让同一个工具(如gcc)的不同版本能在系统中共存,在需要的时候切换到对应的版本中,是不是有点像 rvm(ruby) 或者 nvm(node)呢,不过这个可是系统级别的哦,对所有软件都适用。
1、安装 系统centos7测试的
[root@111 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@111 ~]#
安装vim插件
yum -y install yum-plugin-priorities
yum -y install epel-release
#安装scl
[root@111 ~]# yum install centos-release-scl-rh centos-release-scl
查看这两个软件往我们系统装写了什么东西
[root@111 ~]# rpm -ql centos-release-scl
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
/etc/yum.repos.d/CentOS-SCLo-scl.repo
/usr/share/doc/centos-release-scl/GPL
[root@111 ~]# rpm -ql centos-release-scl-rh
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo
/etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
/usr/share/doc/centos-release-scl-rh/GPL
#安装 scl工具
[root@111 yum.repos.d]# yum install scl-utils scl-utils-build
[root@111 yum.repos.d]# rpm -ql scl-utils
/etc/bash_completion.d/scl.bash
/etc/scl/conf
/etc/scl/prefixes
/opt/rh
/usr/bin/scl
/usr/bin/scl_enabled
/usr/bin/scl_source
/usr/share/man/man1/scl.1.gz
[root@111 yum.repos.d]# rpm -ql scl-utils-build
/etc/rpm/macros.scl
/usr/lib/rpm/brp-scl-compress
/usr/lib/rpm/brp-scl-python-bytecompile
/usr/lib/rpm/fileattrs/scl.attr
/usr/lib/rpm/scldeps.sh
测试安装高版本php7.4
#查看centos7系统自带的php版本 这个版本的php来自系统自带的版本5.4
[root@111 ~]# php -v
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
#安装高版本php
[root@111 ~]# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
#查看安装了那些源
[root@111 ~]# rpm -ql remi-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-remi
/etc/pki/rpm-gpg/RPM-GPG-KEY-remi2017
/etc/pki/rpm-gpg/RPM-GPG-KEY-remi2018
/etc/yum.repos.d/remi-glpi91.repo
/etc/yum.repos.d/remi-glpi92.repo
/etc/yum.repos.d/remi-glpi93.repo
/etc/yum.repos.d/remi-glpi94.repo
/etc/yum.repos.d/remi-modular.repo
/etc/yum.repos.d/remi-php54.repo
/etc/yum.repos.d/remi-php70.repo
/etc/yum.repos.d/remi-php71.repo
/etc/yum.repos.d/remi-php72.repo
/etc/yum.repos.d/remi-php73.repo
/etc/yum.repos.d/remi-safe.repo
/etc/yum.repos.d/remi.repo
#安装php73
yum --enablerepo=remi-safe search php73
yum --enablerepo=remi-safe -y install php73 php73-php-pear php73-php-mbstring
#使用scl查看
[root@111 ~]# scl --list
php73
#启用
[root@111 ~]# scl enable php73 bash #会在当前bash运行
[root@111 ~]# php -v #查看php版本
PHP 7.3.8 (cli) (built: Jul 30 2019 09:26:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.8, Copyright (c) 1998-2018 Zend Technologies
[root@111 ~]# which php
/opt/remi/php73/root/usr/bin/php
#如果要开机运行这个版本需要添加环境变量 到变量 .bash_profile 或者 /etc/profile
source /opt/remi/php73/enable
安装高版本gcc
查看当前的gcc版本
[root@111 ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
查看scl仓库gcc版本
[root@111 yum.repos.d]# yum list all --disablerepo=* --enablerepo=centos-sclo-rh |grep gcc
[root@111 yum.repos.d]# yum list all --disablerepo=* --enablerepo=centos-sclo-rh |grep devtoolset-8
Repository epel is listed more than once in the configuration
devtoolset-8.x86_64 8.1-1.el7 @centos-sclo-rh
devtoolset-8-binutils.x86_64 2.30-54.el7 @centos-sclo-rh
devtoolset-8-binutils-devel.x86_64 2.30-54.el7 @centos-sclo-rh
devtoolset-8-build.x86_64 8.1-1.el7 @centos-sclo-rh
devtoolset-8-dwz.x86_64 0.12-1.1.el7 @centos-sclo-rh
devtoolset-8-dyninst.x86_64 9.3.2-6.el7 @centos-sclo-rh
#安装
yum -y install devtoolset-8-* --enablerepo=centos-sclo-rh
#查看
[root@111 yum.repos.d]# scl --list
devtoolset-8
php73
[root@111 yum.repos.d]# scl enable devtoolset-8 bash
[root@111 yum.repos.d]# 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 --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
#设置为用户环境变量随意切换
source /opt/rh/devtoolset-8/enable