Ask Your Question

Revision history [back]

For configuring alternatives, I follow a slightly different approach to @donniezazen's steps.

Below approach is useful for me as I frequently use other components during Java development.

sudo /usr/sbin/alternatives  \
  --install /usr/bin/java      java        /usr/java/jdk1.8.0_45/bin/java          20000 \
  --slave /usr/lib/jvm/java_home_dir java_home_dir /usr/java/jdk1.8.0_45 \
  --slave /usr/bin/javadoc     javadoc     /usr/java/jdk1.8.0_45/bin/javadoc \
  --slave /usr/bin/javaws      javaws      /usr/java/jdk1.8.0_45/bin/javaws \
  --slave ... add those you need ... keytool / orbd / servertool / rmiregistry ... etc

Full alternatives command is here

Also configure such that JAVA_HOME is switched each time alternatives is used.

sudo vim /etc/profile.d/sun-jdk.sh  

# /etc/profile.d/sun-jdk.sh
#
# Set PATH for Sun JDK

export JAVA_HOME=`realpath /etc/alternatives/java_home_dir`

PATH=$JAVA_HOME/bin:$PATH
export PATH

Don't forget to make the script executable

sudo chmod +x /etc/profile.d/sun-jdk.sh