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

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

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

28条回答
  •  礼貌的吻别
    2020-11-22 16:02

    It is a little bit tricky, but try to follow the steps described in Installing Java on OS X 10.9 (Mavericks). Basically, you gonna have to update your alias to java.

    Step by step:

    After installing JDK 1.7, you will need to do the sudo ln -snf in order to change the link to current java. To do so, open Terminal and issue the command:

    sudo ln -nsf /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents \
    /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
    

    Note that the directory jdk1.7.0_51.jdk may change depending on the SDK version you have installed.

    Now, you need to set JAVA_HOME to point to where jdk_1.7.0_xx.jdk was installed. Open again the Terminal and type:

    export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"
    

    You can add the export JAVA_HOME line above in your .bashrc file to have java permanently in your Terminal

提交回复
热议问题