Tuesday, August 5, 2014

Upgrading GCC on Linux Mint 13/Ubuntu 12.04

GCC on Linux Mint 13/Ubuntu 12.04 can be upgraded from the default GCC 4.6.3 by adding the tool chains repository.  Instructions can be found around the Internet, but I will briefly provide procedure that I used.  First, the python‑software‑properties package needs to be installed (it was already installed on my system):
sudo apt-get install python-software-properties
Now the tool chain repository can be added with these commands:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
With this repository, the current GCC 4.6.3 can be upgraded to the most recent of the 4.6 series to 4.6.4.  However, the goal is to get a more recent version.  For this the g++-4.8 package needs to be installed:
sudo apt-get install g++-4.8
This should also bring the other required packages (gcc-4.8-base, gcc-4.8, cpp-4.8 and libstdc++-4.8-dev).  Once the 4.8 packages are installed, they need to be selected, otherwise the 4.6 commands will still be executed.  This is accomplished with the following commands:
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 50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50

For the first time, the first two commands are not needed.  I put these lines into a script file (named usegcc48), and created and second script identical to this except with the "4.8" changed to "4.6" to select the 4.6 commands (named usegcc46).  This way, it is easy to switch between the two versions (the execute bit needs to set on these scripts using the command chmod +x usegcc4*).