How to change the version of Java that CDH uses How to change the version of Java that CDH uses hadoop hadoop

How to change the version of Java that CDH uses


I came here because I was looking for ways to upgrade JDK from 1.7 to 1.8 on the latest Coudera QuickStart VM 5.8 (can't believe they still ship it with JDK1.7 by default!). The hints and suggestions in the above answers helped tremendously - but since they were not listing complete steps to achieve the upgrade - I thought I would add that to help others like me.

So, here is a complete set of steps to upgrade Cloudera QuickStart VM from JDK1.7 to 1.8:

  • check your current JDK version - out-of-the-box it is:

    [cloudera@quickstart ~]$ java -versionjava version "1.7.0_67"Java(TM) SE Runtime Environment (build 1.7.0_67-b01)Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
  • download desired version of JDK1.8.xx - in my case: jdk-8u111-linux-x64.tar.gz

as user 'cloudera':

  • untar and move the resulting jdk1.8.0_111 dir to the /usr/java dir:

    tar xzf jdk-8u111-linux-x64.tar.gz    sudo mv -f jdk1.8.0_111 /usr/java
  • shutdown all Hadoop services:

    $ for x in `cd /etc/init.d ; ls hadoop-*` ; do sudo service $x stop ; done
  • update bigtop-utils file - set JAVA_HOME to your new JDK:

     sudo vi /etc/default/bigtop-utils updated lines: # Override JAVA_HOME detection for all bigtop packages export JAVA_HOME=/usr/java/jdk1.8.0_111
  • update 'cloudera' user's .bash_profile - export JAVA_HOME and add update PATH:

    export JAVA_HOME=/usr/java/jdk1.8.0_111PATH=$JAVA_HOME/bin:$PATH:$HOME/binexport PATH
  • restart your VM

  • check Java version - should be the 1.8 one now:

    [cloudera@quickstart ~]$ java -versionjava version "1.8.0_111"Java(TM) SE Runtime Environment (build 1.8.0_111-b14)Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

By the way, I did not setup the /usr/java/default with the 'latest' sym link as @milk3422 did, for the sake of simplicity, but it would have worked just as well.

thanks!


I hate to answer my own questions, but here is the answer:

The wrong version of $JAVA_HOME is getting set for 2 reasons:

  1. Using the command service removes most environmental variables. From man service:

    service  runs a System V init script in as predictable environment as possible, removing most environment variables and with current work-ing directory set to /.
  2. The /usr/lib/bigtop-utils/bigtop-detect-javahome script has the ability to be configured with the environment variable BIGTOP_JAVA_MAJOR to manually set which version of Java to use. I tried setting this as an environment variable, but service removes it :(. It is also important to note that this script will find all versions of java installed, but the order of preference is Java 6, Java 7, Java 8, Open Java. So if you have Java 6, and 8 installed, it will prefer 6 over 8.

In short, to fix my problem, I added the following to the top of /usr/lib/bigtop-utils/bigtop-detect-javahome:

BIGTOP_JAVA_MAJOR=8

You can also set JAVA_HOME in this file to specify a specific version or path.


I had the same problem. I set

JAVA_HOME=... below the file /usr/lib/bigtop-utils/bigtop-detect-javahome

to override the default detect value. That works great!