Sometimes alternatives does not work in a single command by selecting the desired version of java. I am not sure of the precise reason for this though..
I fell victim to such a scenario.
The auto-pilot failed, we must fly manual now..
In any of below two files in your unix installation add following variables and a call to a shell script (I have provided below) -
~/.bashrc
export JAVA_HOME=/opt/jdk1.8.0_141
export PATH=$JAVA_HOME/bin:$PATH
sudo bash /appl/common/toFixJava.sh
OR
/etc/profile
export JAVA_HOME=/opt/jdk1.8.0_141
export PATH=$JAVA_HOME/bin:$PATH
sudo bash /appl/common/toFixJava.sh
The script below referenced above sets the rest of java modules to utilize the java you want to use -
toFixJava.sh
altrs="java javac jre jarsigner javadoc javafxpackager javah javap java-rmi.cgi javaws jcmd jconsole jcontrol jdb jhat jinfo jmap jmc jmc.ini jps jrunscript jsadebugd jstack jstat jstatd jvisualvm keytool appletviewer apt ControlPanel extcheck idlj native2ascii orbd pack200 policytool rmic rmid rmiregistry schemagen serialver servertool tnameserv unpack200 wsgen wsimport xjc"
for each in $altrs
do
alternatives --install /usr/bin/$each $each /opt/jdk1.8.0_141/bin/$each <desired installation index number, e.g. 2>
alternatives --set $each /opt/jdk1.8.0_141/bin/$each
done
Please do let know if this doesn't work for you. I will help you solve alternatively!