Last active
November 8, 2017 07:58
-
-
Save paulwellnerbou/8b7907c067047ad553c8c97aefc4365d to your computer and use it in GitHub Desktop.
Shell script switching between two Java versions, including JAVA_HOME (which is not handled by update-alternatives)
This file contains 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 | |
set -u | |
JAVA7="/opt/jdk1.7.0_80" | |
JAVA8="/opt/jdk1.8.0_31" | |
# Assuming you have $JAVA_SYMLINK/bin in your path, in this case "/opt/jdk/bin" | |
JAVA_SYMLINK="/opt/jdk" | |
NEW_JAVA=$JAVA7 | |
current=`readlink $JAVA_SYMLINK` | |
echo $current | |
if [ "$current" == "$JAVA7" ]; then | |
NEW_JAVA=$JAVA8 | |
fi | |
echo "$current -> $NEW_JAVA" | |
unlink $JAVA_SYMLINK | |
ln -s $NEW_JAVA $JAVA_SYMLINK | |
java -version | |
which java | |
echo $JAVA_HOME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment