MAC Homebrew 安裝 Java8

Homebrew 安裝 Java8

brew tap adoptopenjdk/openjdk

brew cask install adoptopenjdk8

如果提示兩個(gè) tap 沖突,使用 untap 命令:

brew untap ... 

JAVA_HOME

編輯 .bash_profile,添加 JAVA_HOME:

# JDK 8
export JAVA_HOME_8=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home 
export JAVA_HOME_13=/Library/Java/JavaVirtualMachines/openjdk-13.0.1.jdk/Contents/Home
export PATH=$PATH:$JAVA_HOME_8

alias jdk8="export JAVA_HOME=$JAVA_HOME_8"
alias jdk13="export JAVA_HOME=$JAVA_HOME_13"

刷新配置:

source ~/.bash_profile

或者如果是 zsh

source ~/.zshrc

切換版本

?  ~ jdk8
?  ~ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)

?  ~ jdk13
?  ~ java -version
openjdk version "13.0.1" 2019-10-15
OpenJDK Runtime Environment (build 13.0.1+9)
OpenJDK 64-Bit Server VM (build 13.0.1+9, mixed mode, sharing)

默認(rèn)選擇低版本Java

https://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-os-x

Solution without 3rd party tools:
leave all JDKs at their default location, under /Library/Java/JavaVirtualMachines. The system will pick the highest version by default.
To exclude a JDK from being picked by default, rename its Contents/Info.plist to Info.plist.disabled. That JDK can still be used when $JAVA_HOME points to it, or explicitly referenced in a script or configuration. It will simply be ignored by system's java command.
System launcher will use the JDK with highest version among those that have an Info.plist file.

When working in a shell with alternate JDK, pick your method among existing answers (jenv, or custom aliases/scripts around /usr/libexec/java_home, etc).

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容