Alternatives has the notion of master and slave configurations. The way that the OpenJDK sets up the alternatives is that it uses 2 masters 'java' for the runtime (JRE) and 'javac' for the development tools (JDK). To set the Oracle JDK in a similar way you need a script like this:
Once you have run that script then you can configure the JRE and JDK of your choice:
$ sudo alternatives --config java
Which will provide a prompt allowing you to choose your desired JRE
There is 2 program that provides 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.60...
+ 2 /usr/java/latest/jre/bin/java
Enter to keep the current selection[+], or type selection number:
And run the same thing for the JDK:
$ sudo alternatives --config javac
8 comments:
Jesus !
It's quiet easy to switch between jdk in gentoo:
$ java-config-2 -L
The following VMs are available for generation-2:
1) GCJ 4.7.2 [gcj-jdk]
2) IcedTea JDK 6.1.12.4 [icedtea-6]
3) IcedTea JDK 7.2.3.9 [icedtea-7]
*) Oracle JDK 1.7.0.45 [oracle-jdk-bin-1.7]
5) Sun JDK 1.6.0.45 [sun-jdk-1.6]
$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)
$ java-config-2 -s 1
Now using gcj-jdk as your user JVM
$ java -version
java version "1.5.0"
gij (GNU libgcj) version 4.7.2
On my Ubuntu based distro, I often do this and it works:
for binary in $(ls /usr/lib/java/jdk1.7.0_51/bin/); do sudo update-alternatives --install /usr/bin/$binary $binary /usr/lib/java/jdk1.7.0_51/bin/$binary 0; done
I just add my different Java environments in my .bashrc and select which one I want to use.
I always remove the installed one because they are installed at impractical locations.
JAVA_HOME=/java/jdk/jdk1.7.0_51/
#JAVA_HOME=/java/jdk/jdk1.8.0/
PATH=$JAVA_HOME/bin:$PATH
Hi, Nice blog I had a great time reading it. Would you please consider adding a link to my website on link list? Please email me back. Thanks!
Randy
randydavis387 at gmail.com
update-java-alternatives
When I see posts like this and so many confusions about alternatives I completely agree with Peter Veentjer here. .bashrc is the most simple and least surprise approach. It is also cross-platform solution and working fine on windows, see http://ggajos.com/environment-variables-management/
Post a Comment