#!/bin/bash JAVA_6_HOME=/usr/lib/jvm/java-6-openjdk-amd64/ JAVA_7_HOME=/usr/lib/jvm/java-7-openjdk-amd64/ JAVA_8_HOME=/usr/lib/jvm/java-8-openjdk-amd64/ echo -e "\n输入编号以选择JDK版本:\n\t1. JDK6($JAVA_6_HOME) \n\t2. JDK7($JAVA_7_HOME) \n\t3. JDK8($JAVA_8_HOME)\n" echo -n "直接回车会直接选择JDK7:" read jdk_version case $jdk_version in jdk6|1) export JAVA_HOME=$JAVA_6_HOME sudo rm /usr/bin/java && sudo ln -s $JAVA_6_HOME/bin/java /usr/bin/java sudo rm /usr/bin/javac && sudo ln -s $JAVA_6_HOME/bin/javac /usr/bin/javac ;; jdk7|2) export JAVA_HOME=$JAVA_7_HOME sudo rm /usr/bin/java && sudo ln -s $JAVA_7_HOME/bin/java /usr/bin/java sudo rm /usr/bin/javac && sudo ln -s $JAVA_7_HOME/bin/javac /usr/bin/javac ;; jdk8|3) export JAVA_HOME=$JAVA_8_HOME sudo rm /usr/bin/java && sudo ln -s $JAVA_8_HOME/bin/java /usr/bin/java sudo rm /usr/bin/javac && sudo ln -s $JAVA_8_HOME/bin/javac /usr/bin/javac ;; *) export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/ sudo rm /usr/bin/java && sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/bin/java /usr/bin/java sudo rm /usr/bin/javac && sudo ln -s /usr/lib/jvm/java-7-openjdk-amd64/bin/javac /usr/bin/javac ;; esac export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib java -version |