Skip to content

Instantly share code, notes, and snippets.

@cristiarg
Last active January 29, 2021 11:05
Show Gist options
  • Save cristiarg/bd9958913180a43c17a734c2e93674bf to your computer and use it in GitHub Desktop.
Save cristiarg/bd9958913180a43c17a734c2e93674bf to your computer and use it in GitHub Desktop.
Configure multiple GCC versions on Ubuntu
#!/usr/bin/env bash
#sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
#sudo apt update
# find out what points to what
# an indirect way of finding out if alternatives are currently involved
update-alternatives --display gcc
update-alternatives --display g++
update-alternatives --display cc
update-alternatives --display c++
namei `which gcc`
namei `which g++`
namei `which cc`
namei `which c++`
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
# install latest from repo
sudo apt-get install gcc g++
# install other desired version from repo
sudo apt-get install gcc-8 g++-8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 80
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 90
sudo update-alternatives --set cc /usr/bin/gcc
sudo update-alternatives --set c++ /usr/bin/g++
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment