Installing Oracle JRE or JDK on Debian or Ubuntu systems

Steps for installing the Oracle JDK on Debian-based systems.

Configure your operating system to use the latest build of a Technology Compatibility Kit (TCK) Certified OpenJDK version 8. For example, OpenJDK 8 (1.8.0_151 minimum).
Tip: Although Oracle JRE/JDK 8 is supported, DataStax does more extensive testing on OpenJDK 8. This change is due to the end of public updates for Oracle JRE/JDK 8.
Java 9 is not supported.
The Oracle Java Platform, Standard Edition (JRE or JDK) has been removed from the official software repositories of Ubuntu and only provides a binary (.bin) version. You can get the JRE or JDK from the Java SE Downloads.

  1. Check if Java is installed:
    java -version
    If Oracle Java, the results should look like:
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
  2. To install Oracle Java, go to Oracle Java SE Downloads, accept the license agreement, and download the installer for your distribution.
    Note: If installing the Oracle Java in a cloud environment, accept the license agreement, download the installer to your local client, and then use scp (secure copy) to transfer the file to your cloud machines.
  3. Make a directory for the JDK:
    sudo mkdir -p /usr/lib/jvm
  4. Unpack the tarball and install the JRE or JDK. For example
    sudo tar zxvf jdk-8u65-linux-x64.tar.gz -C /usr/lib/jvm

    The JDK files are installed into a directory called /usr/lib/jvm/jdk-8u_version.

  5. Tell the system that there's a new Java version available:
    sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_version/bin/java" 1

    If updating from a previous version that was removed manually, you many need to execute the above command twice, because you'll get an error message the first time.

  6. Set the new JDK as the default using the following command:
    sudo update-alternatives --config java
  7. Make sure your system is using the correct JRE or JDK:
    java -version
    java version "1.8.0_181"
    Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
    Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)