If there is more than one Java version installed (sometimes some software installed itself), how to easily switch it. In addition to the common settings environment variables, today learned a new way to switch:
Update-alternatives--config Java
Update-alternatives--config Javac
Also, how to install your own Java version:
sudo update-alternatives--install/usr/bin/java Java/opt/jdk1.7.0_67/bin/java 50
sudo update-alternatives--install/usr/bin/javac Javac/opt/jdk1.7.0_67/bin/javac 50
sudo update-alternatives--install/usr/bin/javah javah/opt/jdk1.7.0_67/bin/javah 50
sudo update-alternatives--install/usr/bin/javaws javaws/opt/jdk1.7.0_67/bin/javaws 50
sudo update-alternatives--install/usr/bin/javap JAVAP/OPT/JDK1.7.0_67/BIN/JAVAP 50
----------------------------------------another article----------------------------------------
Since you want to compile 2.1 and 2.3 two code in the same Ubuntu environment, and they are using a Java version of one is 1.5, one is 1.6, so you need to switch before compiling;
The switching method is simple, using the following two commands:
Update-alternatives--config Java
Update-alternatives--config Javac
For example:
[Email protected]:~# update-alternatives--config java
There is 2 choices for the alternative Java (Providing/usr/bin/java).
Select Path Priority state
------------------------------------------------------------
* 0/usr/lib/jvm/java-6-sun/jre/bin/java 63 Auto Mode
1/usr/lib/jvm/java-1.5.0-sun/jre/bin/java 53 Manual Mode
2/usr/lib/jvm/java-6-sun/jre/bin/java 63 Manual Mode
To maintain the current value [*] press ENTER, or type the number of your choice: 1
Update-alternatives: Use/usr/lib/jvm/java-1.5.0-sun/jre/bin/java to provide/usr/bin/java (Java) in manual mode.
Just enter the number you want to switch to enter, do not change the words directly enter, don't forget Javac also changed ~
After the change,
Java-version
Javac-version
Javac Java version switching