Using alternatives on linux

Multiple applications with the same name can be used with alternatives.

For example, if you want to install several versions of gcc, alternatives support
switching between multiple versions with one command.

  1. List which versions of gcc are installed
  2. ls /usr/bin/gcc*

  3. Add several alternatives for gcc
  4. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.1 30

  5. Select which version of gcc should be selected
  6. sudo update-alternatives --config gcc

  7. Add alternatives for g++, i486-linux-gnu-gcc and i486-linux-gnu-g++
  8. update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 40
    update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.1 30
    update-alternatives --config g++

    update-alternatives --install /usr/bin/i486-linux-gnu-gcc i486-linux-gnu-gcc /usr/bin/i486-linux-gnu-gcc-4.4 40
    update-alternatives --install /usr/bin/i486-linux-gnu-gcc i486-linux-gnu-gcc /usr/bin/i486-linux-gnu-gcc-4.1 30
    update-alternatives --config i486-linux-gnu-gcc

    update-alternatives --install /usr/bin/i486-linux-gnu-g++ i486-linux-gnu-g++ /usr/bin/i486-linux-gnu-g++-4.4 40
    update-alternatives --install /usr/bin/i486-linux-gnu-g++ i486-linux-gnu-g++ /usr/bin/i486-linux-gnu-g++-4.1 30
    update-alternatives --config i486-linux-gnu-g++

Internally, the alternatives are handled as symbolic links and the link is changed, if the config is updated.