728x90

현재 설치된 JDK 버전 목록 확인

/usr/libexec/java_home -V

아래 스크립트를 복붙!

javahome_usage() {
        echo "javahome - switch to different JDK version"
        echo "Usage: javahome [-h] [-v VERSION]" 
        echo echo " -h : display usage" 
        echo " -v : specific JDK version to switch" 
        echo echo "Examples: " 
        echo "># javahome -v 1.8 : switches to JDK8" 
        echo "># javahome -v 11 : switches to JDK11"
				echo "># javahome -v 16 : switches to JDK16"
				echo "># javahome -v 17 : switches to JDK17"
        echo "># javahome : display all installed JDK and display current JDK" 
}
jhome () {
    if [ "$1" = "-h" ] ; then
        jhome_usage
    fi
    if [ "$#" -eq 0 ] ; then
        /usr/libexec/java_home -V
    fi

    if [ "$#" -eq 2 ] && [ "$1" = "-v" ] ; then
        export JAVA_HOME=`/usr/libexec/java_home $@`
        echo "Setting JAVA_HOME:" $JAVA_HOME
        echo 
        echo "Added JAVA_HOME/bin to PATH"
        PATH=$PATH:$JAVA_HOME/bin
        echo $PATH
        echo 
        java -version
    fi
}14

아래와같이 출력된다

Setting JAVA_HOME: /Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home

Added JAVA_HOME/bin to PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/bin:/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home/bin

openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment AdoptOpenJDK (build 14.0.2+12)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 14.0.2+12, mixed mode, sharing)

+ Recent posts