How to set or change the default Java (JDK) version on OS X?

后端 未结 28 2608
渐次进展
渐次进展 2020-11-22 15:55

How can you change the default version of Java on a mac?

28条回答
  •  执念已碎
    2020-11-22 16:02

    An easy way to include a separately installed JDK in the list given by /usr/libexec/java_home -V is to symlink the directory as follows:

    sudo ln -s path/to/jdk /Library/Java/JavaVirtualMachines/jdk-[some-identifier].jdk
    

    For example, to register the JDK included with Android Studio (1.8.0_152 at the time of writing), use:

    sudo ln -s /Applications/Android\ Studio.app/Contents/jre/jdk /Library/Java/JavaVirtualMachines/jdk-android-studio.jdk
    

    Now java_home will list the JDK under Matching Java Virtual Machines and you can select it as described above.

提交回复
热议问题