Wednesday, August 17, 2011

How to have multiple versions of gcc and switch from one version to other

First download the gcc packages
for example: cpp-3.4_3.4.4-6ubuntu8_i386.deb (1707096 bytes)
gcc-3.4_3.4.4-6ubuntu8_i386.deb (484408 bytes)
gcc-3.4-base_3.4.4-6ubuntu8_i386.deb (163028 bytes)

mkdir ~/gcc-3.4

cd ~/gcc-3.4

sudo apt-get install build-essential

dpkg-scanpackages   .   /dev/null | gzip -9c > Packages.gz

sudo gedit /etc/apt/sources.list

add the following code to the file:
deb file:///home/username/gcc-3.4 ./

replace the username with your user name

sudo apt-get update
sudo apt-get install gcc-3.4


Now you have 2 versions of gcc

Now list all the gcc that is available
$ls /usr/bin/gcc* -l

Now type

$ sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-4.2 40
$ sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-3.4 30


this will set both the gcc versions

now to switch from one gcc version to another perform

sudo update-alternatives --config



 
Now enter the number of whichever gcc you want.

I believe this will work for other packages also.
Powered By Blogger