Comment
Author: Admin | 2025-04-28
To ensure compatibility.Configure Alternative Versions of GCCYou may need to install multiple GCC compiler versions as a developer or specific user. Follow these steps to configure alternative versions of GCC on your Ubuntu system.First, install the versions of GCC you need. You can install multiple versions of GCC along with G++ using the following command:sudo apt install gcc-9 g++-9 gcc-10 g++-10 gcc-11 g++-11 g++-12 gcc-12 g++-13 gcc-13 g++-14 gcc-14Note: This is an example command and should be modified to suit your requirements.Once you have installed the necessary versions, use the update-alternatives command to configure each version’s priority. The following example command sets the priority split between GCC 9, GCC 10, GCC 11, GCC 12, GCC 13, and the latest GCC 14. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 90 --slave /usr/bin/g++ g++ /usr/bin/g++-14 --slave /usr/bin/gcov gcov /usr/bin/gcov-13sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 80 --slave /usr/bin/g++ g++ /usr/bin/g++-13 --slave /usr/bin/gcov gcov /usr/bin/gcov-13sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100 --slave /usr/bin/g++ g++ /usr/bin/g++-12 --slave /usr/bin/gcov gcov /usr/bin/gcov-12sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 70 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 --slave /usr/bin/g++ g++ /usr/bin/g++-10 --slave /usr/bin/gcov gcov /usr/bin/gcov-10sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50 --slave /usr/bin/g++ g++ /usr/bin/g++-9 --slave /usr/bin/gcov gcov /usr/bin/gcov-9The above commands set GCC 12 as the highest priority with a value of 100. However, you can configure the priorities based on your preferences, such as if you need to work with the latest releases, GCC 13 or 14.To confirm that GCC 12 is the default version on your system, run the following command:gcc --versionExample output:How to check the GCC compiler version on UbuntuYou can reconfigure the default GCC version on your system by using the update-alternatives command. First, use the following command to list the priorities you previously set:sudo update-alternatives --config gccExample output:Command
Add Comment