Skip to main content

How to Switch Various Compiles (Java, GCC, G++) Version Conveniently?

How to switch various compiles (Java, GCC, G++) version conveniently?

How to switch various compiles (Java, GCC, G++) version conveniently?

Introduction

This essay will focus on the 'update-alternatives' of the manipulation. If you are a developer and you are often to encounter many compilers. That's very messed up things. Thus, although it is true that many compilers make difficult up, the tool (update-alternatives) will help you to cost down many times.

Equipment

Operation System: Ubuntu 14.04 LTS

Usage

1.. Generally, The tool (update-alternatives) has been installed your Linux system. It is a very usefully tool and it is able to help you easily switch to different compilers. Of course, you need to make sure you have the tool.

$ sudo update-alternatives --version
Debian update-alternatives version 1.16.15.

This is free software; see the GNU General Public License version 2 or later for copying conditions. There is NO warranty.

2.. Moreover, you have tried to install more than one compilers. For example, you will install various kinds of the compilers, such as gcc, g++, Java, Open JDK, etc.

$ sudo apt-get install gcc-4.4 gcc-4.6 gcc-4.7 gcc-4.8 g++-4.4 g++-4.6 g++-4.7 g++-4.8

3.. Nonetheless, just only one can be a symbolic link. Let me explain more detail about how to set up the tool. Now, you will install symbol links for those compilers respectively.

3.1. Installation a symbolic link.
In this case, you can follow the format of parameters as below.
Format: sudo (change to be a root) update-alternatives (the tool name) –install (To make up a symbolic link) /usr/bin/gcc (your gcc symbol link) gcc (a configuration name) /usr/bin/gcc-4.4 (your gcc installation path) 1 (priority)

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 1
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 4
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 5
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 2

4.. The choice you want to a compiler to be default.

$ sudo update-alternatives --config gcc

There are 4 choices for the alternative gcc (providing /usr/bin/gcc).   

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-4.7   5         auto mode
  1            /usr/bin/gcc-4.4   1         manual mode
  2            /usr/bin/gcc-4.6   4         manual mode
  3            /usr/bin/gcc-4.7   5         manual mode
* 4            /usr/bin/gcc-4.8   2         manual mode

Press enter to keep the current choice[*], or type selection number:    

5.. Notwithstanding the initial confusion, the tool (update-alternatives) was a success. I think you should spend a few times doing this, because you will be to earn more time to develop.

$ sudo update-alternatives --config java

There are 8 choices for the alternative java (providing /usr/bin/java).


  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  3            /usr/lib/jvm/jdk1.6.0_37-i586/bin/java           1         manual mode
  4            /usr/lib/jvm/jdk1.6.0_37-x64/bin/java            2         manual mode
  5            /usr/lib/jvm/jdk1.6.0_45-i586/bin/java           3         manual mode
  6            /usr/lib/jvm/jdk1.6.0_45-x64/bin/java            4         manual mode
  7            /usr/lib/jvm/jdk1.7.0_67-i586/bin/java           5         manual mode
  8            /usr/lib/jvm/jdk1.7.0_67-x64/bin/java            6         manual mode

Press enter to keep the current choice[*], or type selection number:

$ sudo update-alternatives --config javac

There are 8 choices for the alternative javac (providing /usr/bin/javac).


  Selection    Path                                         Priority   Status
------------------------------------------------------------

  0            /usr/lib/jvm/java-7-openjdk-amd64/bin/javac   1071      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/bin/javac   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-amd64/bin/javac   1071      manual mode
  3            /usr/lib/jvm/jdk1.6.0_37-i586/bin/javac       1         manual mode
  4            /usr/lib/jvm/jdk1.6.0_37-x64/bin/javac        2         manual mode
  5            /usr/lib/jvm/jdk1.6.0_45-i586/bin/javac       3         manual mode
  6            /usr/lib/jvm/jdk1.6.0_45-x64/bin/javac        4         manual mode
  7            /usr/lib/jvm/jdk1.7.0_67-i586/bin/javac       5         manual mode
  8            /usr/lib/jvm/jdk1.7.0_67-x64/bin/javac        6         manual mode

Press enter to keep the current choice[*], or type selection number:

$ sudo update-alternatives --config javaws

    
There are 8 choices for the alternative javaws (providing /usr/bin/javaws).

  Selection    Path                                              Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws   1071      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/javaws   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/javaws   1071      manual mode
  3            /usr/lib/jvm/jdk1.6.0_37-i586/bin/javaws           1         manual mode
  4            /usr/lib/jvm/jdk1.6.0_37-x64/bin/javaws            2         manual mode
  5            /usr/lib/jvm/jdk1.6.0_45-i586/bin/javaws           3         manual mode
  6            /usr/lib/jvm/jdk1.6.0_45-x64/bin/javaws            4         manual mode
  7            /usr/lib/jvm/jdk1.7.0_67-i586/bin/javaws           5         manual mode
  8            /usr/lib/jvm/jdk1.7.0_67-x64/bin/javaws            6         manual mode

Press enter to keep the current choice[*], or type selection number:

$ sudo update-alternatives --config gcc

    
There are 4 choices for the alternative gcc (providing /usr/bin/gcc).

  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/gcc-4.7   5         auto mode
  1            /usr/bin/gcc-4.4   1         manual mode
  2            /usr/bin/gcc-4.6   4         manual mode
  3            /usr/bin/gcc-4.7   5         manual mode
* 4            /usr/bin/gcc-4.8   2         manual mode

Press enter to keep the current choice[*], or type selection number:

$ sudo update-alternatives --config g++

    
There are 4 choices for the alternative g++ (providing /usr/bin/g++).



  Selection    Path              Priority   Status
------------------------------------------------------------
  0            /usr/bin/g++-4.7   5         auto mode
  1            /usr/bin/g++-4.4   1         manual mode
  2            /usr/bin/g++-4.6   4         manual mode
  3            /usr/bin/g++-4.7   5         manual mode
* 4            /usr/bin/g++-4.8   2         manual mode

Press enter to keep the current choice[*], or type selection number:

6.. Finally, If you want to understand the tool, you could run this command-line.

$ sudo update-alternatives --help

Usage: update-alternatives [< option > ...] < command >    
Commands:    
  --install < link > < name > < path > < priority >    
    [--slave < link > < name > < path >] ...    
                           add a group of alternatives to the system.   
  --remove < name > < path >   remove < path > from the < name > group   
(...more)    
automatically,    
       do this as root:    
              update-alternatives --auto vi     

Acknowledge

Thank you (Ask Ubuntu) very much for this great tool.

Popular posts from this blog

Python 日期與時間的處理

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Python 日期與時間的處理

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (10. 條碼列印程式)

Image

寫作:波蘭文學習之旅:1-1. 波蘭文字母與發音(注音版)

Image

數位影像處理:最佳化處理策略之快速消除扭曲演算法

Image

用10種程式語言做影像二值化(Image binarization)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (04. 人事考勤管理系統)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (06. 題庫測驗系統)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (11. 生產線拍照程式)

Image

Visual Basic 6.0 (VB6) 程式語言案例學習 (07. 收據列印程式)

Image

Visual Basic .Net (VB.Net) 程式語言案例學習 (03. 場地預約系統)

Image