-
Notifications
You must be signed in to change notification settings - Fork 2
Ubuntu: live with multiple versions of gcc etc.
Wenliang ZHANG edited this page Jun 11, 2021
·
5 revisions
In the old good days, *Nix users tend to use chroot to deploy mutiple verions of development tools GCC with chroot. And Red Hat had made the life much easier with devtools. But Ubuntu has its own solution.
How to choose the default gcc version
- Remove the alternatives
for x in gcc g++ x86_64-linux-gnu-gcc x86_64-linux-gnu-g++ gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool do sudo update-alternatives --remove-all $x done
- Install all of the versions
sudo apt-get install gcc-4.8 gcc-5 gcc-7 gcc-6 gcc-8 gcc-9 g++-4.8 g++-5 g++-6 g++-7 g++-8 g++-9
- Update the alternatives
for x in gcc g++ x86_64-linux-gnu-gcc x86_64-linux-gnu-g++ gcc-ar gcc-nm gcov gcov-dump gcov-tool do priority=0 for version in 4.8 5 6 7 8 9 do priority=$(($priority + 10)) sudo update-alternatives --install /usr/bin/$x $x /usr/bin/$x-$version $priority done done sudo update-alternatives --install /usr/bin/ranlib ranlib /usr/bin/x86_64-linux-gnu-ranlib 10
- Change the default gcc/g++ when needed:
for x in gcc g++ x86_64-linux-gnu-gcc x86_64-linux-gnu-g++ gcc-ar gcc-nm gcov gcov-dump gcov-tool do sudo update-alternatives --config $x done
- Notes
Not found: gcc-ar-4, gcc-nm-4, gcov-dump-4, gcov-tool-4.
gcc-ar, gcc-ar-5, gcc-ar-7 are 2.26.1 gcc-nm, gcc-nm-4, gcc-nm-7 are 2.26.1. gcov-dump-5, gcov-dump-7 are 5 and 7. gcov-tool-5, gcov-tool-7 are 5 and 7.
The same logic can be applied to other software like bison, clang etc.
Created by Wenliang Zhang.