查看安装了那些系统
java
/usr/libexec/java_home -V
例如
powershell
Mac ~ % /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
18.0.1.1 (x86_64) "Oracle Corporation" - "Java SE 18.0.1.1" /Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home
17.0.12 (x86_64) "Oracle Corporation" - "Java SE 17.0.12" /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
1.8.0_382 (x86_64) "Amazon" - "Amazon Corretto 8" /Users/wangpeijian/Library/Java/JavaVirtualMachines/corretto-1.8.0_382/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home
在终端中运行以下命令,这将设置 JAVA_HOME 环境变量为 Java 17:
powershell
export JAVA_HOME=$(/usr/libexec/java_home -v 17)
确认切换是否成功,运行:
java -version