Tutorials

How to downgrade GCC and G++ in Ubuntu?

Pinterest LinkedIn Tumblr

Downgrading GCC and G++ compilers in Ubuntu is mandatory to build some packages (like IRSTLM, Giza++, Moses, etc.). In this tutorial, I will present an easy way to install gcc-4.4, gcc-4.6, gcc-4.9, g++-4.4, g++-4.6, and, g++-4.9.

First of all, you need to update the sources repository using a text editor like vi as follow:

    vi /etc/apt/sources.list

At the end of the file, just append the following lines:

    #gcc-4.9 g++-4.9 g++-4.9-multilib
    deb http://dk.archive.ubuntu.com/ubuntu xenial main
    deb http://dk.archive.ubuntu.com/ubuntu xenial universe

    #gcc-4.4 g++-4.4 g++-4.4-multilib
    deb http://dk.archive.ubuntu.com/ubuntu/ trusty main universe
    deb http://dk.archive.ubuntu.com/ubuntu/ trusty-updates main universe

    #gcc-4.6 g++-4.6 g++-4.6-multilib
    deb http://dk.archive.ubuntu.com/ubuntu/ precise main universe
    deb http://dk.archive.ubuntu.com/ubuntu/ precise-updates main universe

To save just type escape, and then enter wq! to quit vi with saving mode.

To update the repository, just run the following command:

    sudo apt-get update

Now, to install gcc-4.4, gcc-4.6, gcc-4.9, g++-4.4, g++-4.6, and, g++-4.9, just run the following commands:

    sudo apt-get install gcc-4.9 g++-4.9 g++-4.9-multilib
    sudo apt-get install gcc-4.4 g++-4.4 g++-4.4-multilib
    sudo apt-get install gcc-4.6 g++-4.6 g++-4.6-multilib

At this stage, you completed the setup of different versions of gcc and g++ in your OS. To select a default gcc and g++ compiler, we need to configure the alternative options of compilers through the following commands:

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 50
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 50
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 50
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 50
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 50
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 50

To change the default gcc version, just run the command:

    sudo update-alternatives --config gcc

and select through the keypad (1, 2, 3, 4, etc.) the version of gcc and same for g++ as follow:

    sudo update-alternatives --config g++

I hope that you enjoyed this tutorial.

Don’t forget to visit my channel on YouTube for more tutorials.

Write A Comment