#install new versions of gcc and g++ sudo apt-get install gcc-5 gcc g++-5 g++ #remove existing alternatives sudo update-alternatives --remove-all gcc sudo update-alternatives --remove-all g++ #add new and old version to update-alternatives db sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50 --slave /usr/bin/g++ g++ /usr/bin/g++-5 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-6 #choose the needed version sudo update-alternatives --config gcc