Last active
December 10, 2015 21:03
-
-
Save samukasmk/460f2c8096196a69da43 to your computer and use it in GitHub Desktop.
Defining Java's version by alternatives tool
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# By: Samuel Maciel Sampaio <[email protected]> [20150122] | |
# Defining Java's version by alternatives tool | |
# Set HERE the REAL PATH to JDK FILES UNCOMPRESSED AND JAVA version you want to configure! | |
REAL_JDK_PATH="/usr/lib/jvm/java-1.8.0-oraclejdk-1.8.0_66" | |
JAVA_VERSION="1.8.0_66" | |
ALTERNATIVES_TOOL=$(which update-alternatives 2>/dev/null) | |
if [ -z "${ALTERNATIVES_TOOL}" ]; | |
then | |
ALTERNATIVES_TOOL=$(which alternatives 2>/dev/null) | |
if [ -z "${ALTERNATIVES_TOOL}" ]; | |
then | |
echo "Error: Unable to find 'alternatives' program... please install them or put in your \$PATH" | |
fi | |
fi | |
ALTERNATIVES_PRIORITY="99999999" | |
JAVA_BINS=$(sudo ls -1 ${REAL_JDK_PATH}/bin | sed s/'java$'/''/g | grep -v 'keytool') | |
ALTERNATIVE_CMD="${ALTERNATIVES_TOOL} --install /usr/bin/java java ${REAL_JDK_PATH}/bin/java ${ALTERNATIVES_PRIORITY}" | |
for JAVA_BIN in $JAVA_BINS; | |
do | |
ALTERNATIVE_CMD="${ALTERNATIVE_CMD} --slave /usr/bin/${JAVA_BIN} ${JAVA_BIN} ${REAL_JDK_PATH}/bin/${JAVA_BIN}" | |
sudo ${ALTERNATIVES_TOOL} --remove-all ${JAVA_BIN} > /dev/null 2>&1 | |
done | |
OTHER_MASTERS="keytool" | |
for MASTER_BIN in $OTHER_MASTERS; | |
do | |
# sudo ${ALTERNATIVES_TOOL} --remove-all ${MASTER_BIN} > /dev/null 2>&1 | |
sudo ${ALTERNATIVES_TOOL} --install /usr/bin/${MASTER_BIN} ${MASTER_BIN} ${REAL_JDK_PATH}/bin/${MASTER_BIN} ${ALTERNATIVES_PRIORITY} | |
done | |
sudo ${ALTERNATIVE_CMD} | |
sudo ${ALTERNATIVES_TOOL} --set java ${REAL_JDK_PATH}/bin/java | |
sudo ${ALTERNATIVES_TOOL} --display java | |
echo "Current JAVA version: `java -version`" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment