0

I installed multiple versions of gcc on a Ubuntu 16.04 and I'm wondering how to set up the system to use the latest version of gcc without uninstalling the older ones.

I'd prefer if it was a simple script and not a dependency because I'm installing it in a Docker container and I don't want to bloat it.

  • Possible duplicate of [How to use multiple versions of GCC](http://stackoverflow.com/questions/448457/how-to-use-multiple-versions-of-gcc) – Pyves Jul 09 '16 at 10:39

1 Answers1

0
# list everything in /usr/bin
# leave the ones that start with gcc
# remove everything but the version numbers
# remove anything but the numbers
# sort them
# get the last one
version=$(ls /usr/bin/ | grep '^gcc' | cut -d'-' -f2 | grep -o '[0-9]\+\(\.[0-9]\+\)\?' | sort | tail -n 1)

# remove the symbolic link to the current version of gcc
rm /usr/bin/gcc

# remove the symbolic link to the current version of g++
rm /usr/bin/g++

# create symbolic links to the latest versions
ln -s /usr/bin/g++-${version} /usr/bin/g++
ln -s /usr/bin/gcc-${version} /usr/bin/gcc