Ubuntu – Switch to Oracle Java JDK in 14.04

14.04jdkoracle

Ubuntu 14.04 comes with OpenJDK after updating from 13.10.

$ java -version  
java version "1.7.0_55"  
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)  
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)  

What is the safest way to switch to Oracle Java JDK? I have some Java developments tools (Eclipse, IntelliJ, Android Studio) and I would not like to break them after switching to Oracle JDK.

The reason for this is because these tool are warning me that I should switch to Oracle JDK to gain performance and to prevent some issue existing in OpenJDK.

Best Answer

Install Oracle/Sun Java. See How can I install Sun/Oracle's proprietary Java JDK 6/7/8 or JRE? (and others) for details.

In a terminal session, run : sudo update-alternatives --config java

You will get a list that looks something like this:

enter image description here

As per the instructions at the prompt, enter the number corresponding to the version you want to be your system default Java implementation.

Once you've done that, unless there are configuration settings directing otherwise for particular applications (quite common), the Java version you've chosen will be your global system default.

I would definitely not recommend removing entirely the OpenJDK. There are any number of modules and applications that may be expecting OpenJDK to be there and are configured to use it - it's the default Java that comes with Ubuntu. Removing it may cause some serious problems. Leave it in place for those modules that expect it, because it is the default. You have set the default to what you want, and you can control the applications you are using to use that setting (in fact you can do it on an application by application basis without changing the system default at all) - but not everything is under your control, at least not without some serious expertise and mucking around.