You could always download and build the version of GCC you want, then add a script in /usr/bin/ to run it. There's other ways of doing this which involves editing the PATH but I am not 100% sure on the details so... script it is I guess. (note: gcc-x.y.z is the version you want to use, IE: gcc-4.9.0. Don't type gcc-x.y.z it will not work)
This article from the OSDev wiki goes over installing a version of GCC (it says newest but you can do any version you want when you download from the ftp mirror).
Start by downloading the version of GCC you want from here.
Extract it into $HOME/src. You should have a gcc folder or something like that in $HOME/src.
Go to gcc-x.y.z/ and execute
This should get the correct versions of the dependencies you need.
Now decide if you want this for just you or globally. If you're just using this you can install it in $HOME/opt/ or globally /usr/local/gcc-x.y.z (I don't think it really matters since we will be placing a script in /usr/bin but don't quote me on that one)
export PREFIX="$HOME/opt/gcc-x.y.z (or the /usr/local/gcc-x.y.z if you're using that as your prefix)
Now, according to the OSDev wiki you want to do
If you wish to build these packages as part of gcc:
mv gmp-x.y.z gcc-x.y.z/gmp
mv mpfr-x.y.z gcc-x.y.z/mpfr
mv mpc-x.y.z gcc-x.y.z/mpc
../gcc-x.y.z/configure --prefix="$PREFIX" --disable-nls --enable-languages=c,c++
Now you can find it in $PREFIX/gcc-x.y.z (should be the $HOME/opt/cross or /usr/local/gcc-x.y.z)
now make a file in /usr/bin called gcc-4.9 (and g++-4.9).
In the script, add
This will pass all the arguments from the command to this version of gcc.
(psst, do the same for the g++ script as well)
Test it out to see if it works. Also if anyone has suggestions in the comments please tell me because I probably made a mistake somewhere.
g++-4.9direct from the
universerepository. You can either call
g++-4.9explicitly or set a variable during compilation e.g.
make 'CXX=/usr/bin/g++-4.9', depending on your software's build system.
universethen install + use