I am writing a script that installs java on a remote machine. After i run the .bin file for the JRE, how can i set the alternatives --config java without the user having to input anything.
For instance, when you type in "alternatives --config java" you are prompted to select which java version you would like. Due to the way i installed java ("/usr/sbin/alternatives --install /usr/bin/java java /location/of/jdk1.6/bin/java 2") the #"2" option should always be the java that i want selected.
So, using an ssh command execution, how can i select the second option for java alternatives without the user having to choose the option. I want it fully automated.
This is in a bash script.
Thanks
Below is the code (working correctly now):
#install the jre
sshRetValue=`ssh -p "22" -i $HOME/sshids/idrsa-1.old ${1} " /home/geiser/jms_adapter/jre-6u25-linux-i586.bin "`;
sshRetValue=`echo $?`;
if [ "$sshRetValue" -eq 0 ];then
echo "java jre installed successfully";
#set the alternative and stuff if needed
ssh -p "22" -i $HOME/sshids/idrsa-1.old ${1} " /usr/sbin/alternatives --install /usr/bin/java java /root/jre1.6.0_25/bin/java 2 ";
echo 2 | ssh -p "35903" -i $HOME/sshids/idrsa-1.old ${1} " alternatives --config java ";
else
echo "java jre installation failed";
fi
You can run the alternatives
command non-interactively too. Instead of --config
, use the --set
option to specify the path of the alternative directly.
sudo alternatives --set java /location/of/jdk1.6/bin/java
This worked for me with Java 8:
alternatives --install /usr/bin/java java /usr/lib/jvm/jre1.8.0_60/bin/java 3
alternatives --config java <<< '3'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With