我的电脑上安装了几个 JDK 来应对不同项目的开发,经常要进行切换,突然发现 macos 上有这么一个工具:
/usr/libexec/java_home
这个工具能够快速查看电脑里安装的所有 JDK:
/usr/libexec/java_home -V
输出大概为:
Matching Java Virtual Machines (3): 21.0.2 (arm64) "GraalVM Community" - "GraalVM CE 21.0.2+13.1" /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home 17.0.13 (arm64) "Amazon.com Inc." - "Amazon Corretto 17" /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home 11.0.5 (x86_64) "Oracle Corporation" - "Java SE 11.0.5" /Library/Java/JavaVirtualMachines/jdk-11.0.5.jdk/Contents/Home 1.8.0_231 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home
这样能够直观的看到安装的多个版本,然后用下面的命令切换:
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
0 条评论