Skip to content

Instantly share code, notes, and snippets.

@nareshganesan
Created March 10, 2017 13:42
Show Gist options
  • Save nareshganesan/fc091f2aef3dfd5ebe7e9854f427f0b1 to your computer and use it in GitHub Desktop.
Save nareshganesan/fc091f2aef3dfd5ebe7e9854f427f0b1 to your computer and use it in GitHub Desktop.
script to swap gcc compiler in ubuntu
# Tested in Ubuntu 14.04
# 14.04 comes with gcc version 4.8.4
# Reference: http://lektiondestages.blogspot.in/2013/05/installing-and-switching-gccg-versions.html
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9
sudo apt-get install g++-4.9
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 10 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9
sudo update-alternatives --config gcc
# or
######################## gcc_set_default_version.bash: start #################################
#!/bin/bash
usage() {
echo
echo Sets the default version of gcc, g++, etc
echo Usage:
echo
echo " gcc-set-default-version <VERSION>"
echo
exit
}
cd /usr/bin
if [ -z $1 ] ; then
usage;
fi
set_default() {
if [ -e "$1-$2" ] ; then
echo $1-$2 is now the default
ln -sf $1-$2 $1
else
echo $1-$2 is not installed
fi
}
for i in gcc cpp g++ gcov gccbug ; do
set_default $i $1
done
########################### gcc_set_default_version.bash: end ################################
# save the above script as gcc_set_default_version.bash and chmod 755 to the script.
sudo sh gcc_set_default_version.bash 4.9 #any version you have in update-alternatives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment