How to install a specific JDK on Mac OS X?

后端 未结 16 879
南方客
南方客 2020-11-29 15:21

I want to install a specific JDK (the latest for example). For this, I went to the JDK download homepage: http://java.sun.com/javase/downloads/index.jsp. I looked for a Mac

16条回答
  •  既然无缘
    2020-11-29 16:04

    Since most answers are out of date, here's what works as of end of 2018 under the assumption that

    1. You want to install the GPL version of OpenJDK.[0]
    2. You do not want to install Homebrew

    In that case, grab the desired version from one the many available, freely usable OpenJDK editions, e.g.:

    • AdoptOpenJDK
    • Amazon Corretto (Great for production, includes backports)
    • Oracle GPLv2 OpenJDK

    Some of these include installers, but if not you can do the following. Assuming here version 11.0.1 for Mac. In your favorite shell, run:

    tar -xzf openjdk-11.0.1_osx-x64_bin.tar.gz
    sudo mv jdk-11.0.1.jdk /Library/Java/JavaVirtualMachines
    # Fix owner and group
    sudo chown -R root:wheel /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk
    # (Optional) Check if the new JDK can be found
    /usr/libexec/java_home
    => /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
    

    [0] Note that the Oracle branded JDK has significant licensing restrictions allowing you its use basically only for testing, i.e., not for production. If you do not have a support agreement with Oracle, then it seems risky to me to use their JDK, especially since the differences to OpenJDK are minimal.

    Edit: added more choices

提交回复
热议问题