Skip to content

Instantly share code, notes, and snippets.

@SunnyRaj
Last active October 10, 2023 09:17
Show Gist options
  • Star 45 You must be signed in to star a gist
  • Fork 28 You must be signed in to fork a gist
  • Save SunnyRaj/788ca494db609a404c9dc4c88d47e775 to your computer and use it in GitHub Desktop.
Save SunnyRaj/788ca494db609a404c9dc4c88d47e775 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
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo apt-get install -y gcc-4.8 g++-4.8 gcc-4.9 g++-4.9 gcc-5 g++-5 gcc-6 g++-6 gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 30
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 40
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 30
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 40
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 50
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++
@bobvo23
Copy link

bobvo23 commented May 27, 2019

Clean and clear. Thank you.

@swissbeats93
Copy link

Not working on Ubuntu 19.10

@dlarue
Copy link

dlarue commented Jan 10, 2020

Indeed, can't get gcc-5 nor g++-5 on Ubuntu 19.10
Trying to build ROS2 and from what I've seen it needs gcc/g++ 5

@wajihullahbaig
Copy link

beautiful. Saved me a lot of hassle.

@cristiarg
Copy link

You could add as a comment the following to investigate existing state:

namei `which cc`
namei `which c++`

@JinYeJin
Copy link

great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment