How To Use Multiple Versions of GCC on openSUSE Leap 16.1
To install old versions of gcc you can download the RPM packets from old repositories and install them.
For example, if you want to install the gcc-7 version of GCC, you search for the packets and their dependencies in the oss repository of openSUSE 15.
You can download the files and install the RPM packets.
:~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libisl15-0.18-lp150.1.49.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libtsan0-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/cpp7-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/gcc7-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libasan4-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libmpx2-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libubsan0-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libcilkrts5-7.3.1+r258812-lp150.2.10.x86_64.rpm :~> wget https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/libmpxwrappers2-7.3.1+r258812-lp150.2.10.x86_64.rpm # rpm -i libtsan0-7.3.1+r258812-lp150.2.10.x86_64.rpm # rpm -i libisl15-0.18-lp150.1.49.x86_64.rpm # rpm -i cpp7-7.3.1+r258812-lp150.2.10.x86_64.rpm # rpm -i libubsan0-7.3.1+r258812-lp150.2.10.x86_64.rpm # rpm -i libmpx2-7.3.1+r258812-lp150.2.10.x86_64.rpm # rpm -i libasan4-7.3.1+r258812-lp150.2.10.x86_64.rpm # rpm -i gcc7-7.3.1+r258812-lp150.2.10.x86_64.rpm
Update-alternatives – How To Use Multiple Versions Of GCC
Now, to be able to use multiple versions of GCC on Linux you have to use update-alternatives.
:~> which gcc-7 /bin/gcc-7 :~> # update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-15 20 # update-alternatives --install /usr/bin/gcc gcc /bin/gcc-7 40 # update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 60 # update-alternatives --set cc /usr/bin/gcc # update-alternatives --config gcc
The version you want in auto mode is the one with the highest number and it will be used automatically. To check the version in use you can run the following command:
:~> gcc --version
