Created
August 16, 2012 17:43
-
-
Save danieldbower/3371994 to your computer and use it in GitHub Desktop.
Switch Java Versions on Debian/Ubuntu
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/sh | |
clear | |
f_o6 () { | |
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64; | |
sudo update-alternatives --set java /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java; | |
} | |
f_s6 () { | |
export JAVA_HOME=/usr/lib/jvm/java-6-sunjdk-amd64; | |
sudo update-alternatives --set java /usr/lib/jvm/java-6-sunjdk-amd64/jre/bin/java; | |
} | |
f_o7 () { | |
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64; | |
sudo update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java; | |
} | |
f_o8 () { | |
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64; | |
sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java; | |
} | |
echo 'To apply to the current shell, be sure to run as:' | |
echo '. javaSwitch.sh' | |
echo | |
echo 'Choose Java version: (6) OpenJDK 6, (6s) SunJDK 6, (7) OpenJDK 7, or (8) OpenJDK 8' | |
read choice | |
case $choice in | |
6) f_o6 ;; | |
6s) f_s6;; | |
7) f_o7;; | |
8) f_o8;; | |
*) echo "\"$choice\" is not valid" | |
esac | |
#sudo update-alternatives --get-selections | grep -i java | |
env | grep JAVA_HOME | |
echo | |
java -version |
Could be easily modified to support non-amd64 platforms but doesn't work as-is.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple but fantastic.