Api Demo | 接口原型

MacOS Homebrew 安装 OpenJDK

2022-03-15T21:57:03
--------------------------------------------------------------------------------------------------------
1、添加仓库

tap 命令说明

添加 AdoptOpenJDK/openjdk 仓库。

$ brew tap AdoptOpenJDK/openjdk

2、查询可用的 JDK 版本
$ brew search openjdk


输出如下:

==> Formulae
openjdk                                                      openjdk@11==> Casks
adoptopenjdk                            adoptopenjdk12                          adoptopenjdk14-jre
adoptopenjdk-jre                        adoptopenjdk12-jre                      adoptopenjdk14-openj9
adoptopenjdk-openj9                     adoptopenjdk12-openj9                   adoptopenjdk14-openj9-jre
adoptopenjdk-openj9-jre                 adoptopenjdk12-openj9-jre               adoptopenjdk14-openj9-jre-large
adoptopenjdk-openj9-jre-large           adoptopenjdk12-openj9-jre-large         adoptopenjdk14-openj9-large
adoptopenjdk-openj9-large               adoptopenjdk12-openj9-large             adoptopenjdk8 ✔
adoptopenjdk10                          adoptopenjdk13                          adoptopenjdk8-jre
adoptopenjdk11                          adoptopenjdk13-jre                      adoptopenjdk8-openj9
adoptopenjdk11-jre                      adoptopenjdk13-openj9                   adoptopenjdk8-openj9-jre
adoptopenjdk11-openj9                   adoptopenjdk13-openj9-jre               adoptopenjdk8-openj9-jre-large
adoptopenjdk11-openj9-jre               adoptopenjdk13-openj9-jre-large         adoptopenjdk8-openj9-large
adoptopenjdk11-openj9-jre-large         adoptopenjdk13-openj9-large             adoptopenjdk9
adoptopenjdk11-openj9-large             adoptopenjdk14



3、选择需要的版本进行安装

brew cask install adoptopenjdk8
brew cask install adoptopenjdk9
brew cask install adoptopenjdk10
brew cask install adoptopenjdk11
brew cask install adoptopenjdk12
brew cask install adoptopenjdk13


如果提示cask已废弃

尝试:

brew install adoptopenjdk/openjdk/adoptopenjdk11


三、查看安装结果

$ /usr/libexec/java_home -V


四、版本配置

vim ~/.bash_profile
export JAVA_HOME_8=$(/usr/libexec/java_home -v1.8)
export JAVA_HOME_13=$(/usr/libexec/java_home -v13)

# Java 8
export JAVA_HOME=$JAVA_HOME_8

# Java 13
# export JAVA_HOME=$JAVA_HOME_13
2、立即生效

$ source ~/.bash_profile
$ java -version

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.252-b09, mixed mode)