Monday, October 24, 2016

How to switch from oracle JDK to open JDK and vice versa

There are two kinds of java development kit or JDK exist in this world, the open source 'open JDK' and the proprietary 'oracle JDK'. You can install both on the same computer, but you can only use one at a time.

So if you already install open JDK on your lubuntu and then for some reasons you need to use oracle JDK (or vice versa), you don't need to uninstall the other one. Because there is a way to switch between one JDK to another.

How to check what JDK currently use
But first let me explain how to check whether what JDK is currently active on your system, you can check by running 'java -version' on the command line, like this
java -version

If you get output something like this:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
That means you are currently running oracle JDK, otherwise if it says something like
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-3ubuntu1~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
That  means you are running open JDK.

How to switch from oracle JDK to open JDK and vice versa
So, now i'm going to show you how to switch between the two JDK, obviously you need to install both on your system and then when you are ready to switch, you can use this command:

sudo update-alternatives --config java

The command above will display all available JDK on your system, you need to choose one of the JDK to activate, simply type the number of the JDK, 0, 1, 2, and so on, and then hit enter.


No comments:

Post a Comment