Ubuntu – Changing JDK from Open JDK to Oracle JDK

android-sdkandroid-studiojdkopenjdk

I installed Android Studio in Ubuntu by following two commands:

  1. sudo apt-get ubuntu-make
  2. umake android

It installed with OpenJDK bydefault using Ubuntu Developer Tool.

Now I want to change JDK from Open JDK to Oracle JDK. Should I do it? If yes, why? If not, then how do I change the JDK to Oracle?

Best Answer

Why choose Oracle Java?

Oracle Java is what most Java projects use. They test their products using it. They don't usually test their products on OpenJDK.

This means that bugs get fixed when they show up on Oracle Java. Bugs don't usually get fixed when they show up only on OpenJDK.

If you want a less buggy experience in general, Oracle Java is a better option.

Installing Oracle Java the nice way

Ubuntu's APT package manager makes it easy to install software, uninstall software, and update software. If you want these benefits with Oracle Java, do the following (replace java8 with the version you want; for example, to get Java 9, install oracle-java9-installer instead):

sudo add-apt-repository ppa:webupd8team/java
sudo apt update
sudo apt install oracle-java8-installer

To switch between installed JDKs

  1. List Java alternatives:

    update-java-alternatives -l
    
  2. Find the line with the Java you want.

  3. Remember the first part of the line. For example, Oracle Java 8's line might look like this on your system:

    java-8-oracle                  1082       /usr/lib/jvm/java-8-oracle
    

    The first part of the line there is java-8-oracle.

  4. Set the first part of the line you want as the Java alternative (replace java-8-oracle with the Java you want):

    sudo update-java-alternatives -s java-8-oracle