Monday, December 2, 2013

Set JDK8 as default java and javac with alternatives

Last post show how to "Install JDK8 Early Access Releases on Raspberry Pi". You can varify installation of the new JDK8 by enter the command:
$ /opt/jdk1.8.0/bin/java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b117)
Java HotSpot(TM) Client VM (build 25.0-b59, mixed mode)

means you have install JDK1.8.0 successfully. But when you enter the command without specifying path:
$ java -version
$ javac -version

It will show the version of the original version, may be 1.7.0_40.

In order to make the new JDK8 as default java and javac, we can run update-alternatives.

- In order to run update-alternatives on Raspberry Pi, we have to "Set password of root", such that we can log-in as root by the command and password:
$su

Then run the commands:
$sudo update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
$sudo update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1

Run the commands to select the expected Java.
$sudo update-alternatives --config javac
$sudo update-alternatives --config java




You can verify your setting by run the Java example in next post to List system properties.

No comments: