in a nutshell, here are some examples for how to install and configure
- for python3 to get python3.9:
dnf install -y python39 && alternatives --set python3 $(command -v python3.9) - for gcc to get gcc-12:
dnf install gcc-toolset-12 && source scl_source enable gcc-toolset-12 - for java to get java-17:
dnf install java-17 && bin_java_filename=$(rpm -qa|grep java-17|xargs rpm -ql|grep "bin\/java$"|head -1) && alternatives --set java ${bin_java_filename} - tested on rocky8, rocky9
which repo has the newer software versions?
- the old method using "SCL" was deprecated
- the new method is to use a repo called "appstream"
- here is a post written by the distro maintainers explaining the change https://developers.redhat.com/blog/2018/11/15/rhel8-introducing-appstreams
- the repo is enabled by default
how to: install newer software versions?
- for python3:
dnf install python39 - for gcc:
dnf install gcc-toolset-12
how to: change the system default?
- for python3:
alternatives --set python3 $(command -v python3.9) - for gcc:
- edit your user
.bashrcor.bash_profileor create a new file under/etc/profile.d/with the following:source scl_source enable gcc-toolset-12 - i thought
scl_sourcewould go away in el8, el9 but apparently not - for more info on
scl_sourcego to this link https://unix.stackexchange.com/a/195219/5510 or Permanently enable RHEL scl
- edit your user
p.s. what is the difference between alternatives and update-alternatives?
- the original tool is called
update-alternativesand is from Debian linux distro - in EnterpriseLinux, Redhat rewrote the tool and called it
alternativesand when you installalternativesthe package also installs a symlink with nameupdate-alternativeson your env varPATHto help you find the tool - the two are similar but not the same because their source code is different
linux - How to permanently enable newer version of software installed from SCL repo? - Unix & Linux Stack Exchange
rhel8 - How to Install devtoolset 8 in RHEL 8 image - Stack Overflow
linux - "scl load gcc-toolset-11" run failed - Stack Overflow
Installing devtoolset-X
In your ~/.bashrc or ~/.bash_profile Simply source the "enable" script provided with the devtoolset. For example, with the Devtoolset 2, the command is:
source /opt/rh/devtoolset-2/enable
or
source scl_source enable devtoolset-2
Lot more efficient: no forkbomb, no tricky shell
An alternative of source /opt/rh/devtoolset-4/enable is
source scl_source enable devtoolset-4
The above shell script scl_source is more elegant than using a hard coded path (may be different on another machine). However scl_source does less because /opt/rh/devtoolset-4/enable uses scl_source and other stuff.
To use scl_source you may have to upgrade package scl-utils
yum update scl-utils # old scl-utils versions miss scl_source
Quick copy-paste
echo 'source scl_source enable devtoolset-4' >> ~/.bashrc
# Do not forget to change the version ↑
Source code for curious people
An example of scl_source source code:
https://gist.github.com/bkabrda/6435016
The scl_source installed on my Red Hat 7.1
#!/bin/bash
_scl_source_help="Usage: source scl_source <action> [<collection> ...]
Don't use this script outside of SCL scriptlets!
Options:
-h, --help display this help and exit"
if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
echo "$_scl_source_help"
return 0
fi
if [ -z "$_recursion" ]; then
_recursion="false"
fi
if [ -z "$_scl_scriptlet_name" ]; then
# The only allowed action in the case of recursion is the same
# as was the original
_scl_scriptlet_name=$1
fi
shift 1
if [ -z "$_scl_dir" ]; then
# No need to re-define the directory twice
_scl_dir=/etc/scl/conf
if [ ! -e $_scl_dir ]; then
_scl_dir=/etc/scl/prefixes
fi
fi
for arg in "$@"; do
_scl_prefix_file=$_scl_dir/$arg
_scl_prefix=`cat $_scl_prefix_file 2> /dev/null`
if [ $? -ne 0 ]; then
echo "Can't read $_scl_prefix_file, $arg is probably not installed."
return 1
fi
# First check if the collection is already in the list
# of collections to be enabled
for scl in ${_scls[@]}; do
if [
scl ]; then
continue 2
fi
done
# Now check if the collection isn't already enabled
/usr/bin/scl_enabled $arg > /dev/null 2> /dev/null
if [ $? -ne 0 ]; then
_scls+=($arg)
_scl_prefixes+=($_scl_prefix)
fi;
done
if [ $_recursion == "false" ]; then
_i=0
_recursion="true"
while [
{#_scls[@]} ]; do
_scl_scriptlet_path="${_scl_prefixes[$_i]}/${_scls[$_i]}/${_scl_scriptlet_name}"
source "$_scl_scriptlet_path"
if [ $? -ne 0 ]; then
echo "Can't source $_scl_scriptlet_name, skipping."
else
export X_SCLS="${_scls[$_i]} $X_SCLS"
fi;
_i=
_i+1))
done
_scls=()
_scl_prefixes=()
_scl_scriptlet_name=""
_recursion="false"
fi
devtoolset is called gcc-toolset in RHEL8.
The following commands worked for me:
microdnf install -y gcc-toolset-12
scl enable gcc-toolset-12 bash
gcc --version
# gcc (GCC) 12.1.1 20220628 (Red Hat 12.1.1-3)
According to that article, you can check if you have access to Red Hat Software Collections (RHSCL) by running the following command by the root user:
$ su -
# subscription-manager repos --list | egrep rhscl
If you have, enable necessary software repo and then install devtoolset:
# subscription-manager repos --enable rhel-7-server-optional-rpms
# yum install devtoolset-8
According to the man page for gcc-toolset-11, it only supports the enable command. It also states that you can run scl gcc-toolset-11 enable bash to execute the bash command with the gcc-toolset-11 environment, which should be equivalent to what the load command would do.
Example:
[root@localhost ~]# scl enable gcc-toolset-11 bash [root@localhost ~]# gcc --version gcc (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9.1.0.3) 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. [root@localhost ~]# exit exit [root@localhost ~]# gcc --version gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18.0.2) Copyright (C) 2018 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. [root@localhost ~]#
Try to use enable instead of load .
See reference: CentOS Software Collections (SCL)
On CentOS I can do yum install devtoolset-8 followed by scl enable devtoolset-8 bash so that my paths are setup to use GCC et al packaged with that development toolset.
Is there an equivalent in AlmaLinux?
I had this problem as well. I don't know why scl was failing to enable the environment, but I was able to get it to load with source /opt/rh/devtoolset-7/enable.
It is because of your settings in .bashrc and/or .bash_profile. scl appends its path to gcc7 before starting your new bash shell, but the path to gcc is default to the old gcc4 again because your .bashrc appends /usr/bin to the path when starting the new bash, and it supersedes the scl settings. The solution is to use the "enable" script directly. That way no further path settings annoy you.
I am using CentOS 7.9 and I encountered the same problem after following instructions here to install and run gcc 11. I tried launching different versions of gcc and found only devtoolset-9 works, which corresponds to the file devtoolset-9 in /etc/scl/conf/ folder. So I copied devtoolset-9 to devtoolset-11 in the same folder, and gcc 11 gets working.
I ran into the same issue that you are facing and this is how I got it fixed:
- Just want to be careful, you need to exist the Terminal and open a fresh one to start. This way, you are not under any devtoolset's bash.
- Go to /opt/rh folder, run command ls -la to see if you have any devtoolset-* folder there. Let's say you have devtoolset-8, proceed step 2.
- Go to /etc/scl/prefixes folder, if you don't see devtoolset-8 file, you can create a new one as devtoolset-8, and type 1 line: /opt/rh, then save and quit that file.
- Once you are done, you can call: scl enable devtoolset-8 -- bash w/o any error. Good luck