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

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

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

相关标签:
28条回答
  • 2020-11-22 16:24

    TOO EASY SOLUTION: What a headache - this was a quick easy solution that worked for me.

    Mac OS Sierra Version 10.12.13

    1. Use the shortcut keys: CMD+SHIFT+G - type in "/Library/"

    2. Find the JAVA folder

    3. Right Click Java Folder = Move to Trash (Password Required)

    4. Install: Java SE Development Kit 8 jdk-8u131-macosx-x64.dmg | Download Javascript SDK

    5. Make sure the new JAVA folder appears in /LIBRARY/
    6. Install Eclipse | Install Eclipse IDE for Java Developers
    7. Boom Done
    0 讨论(0)
  • 2020-11-22 16:27

    Use jenv is an easy way.

    1.Install jenv

    curl -s get.jenv.io | bash
    

    2.Config jenv

    cd ~/.jenv/candidates/
    mkdir java
    cd java
    mkdir 1.7
    mkdir 1.8
    

    3.Symlink the jdk path

    ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin ~/.jenv/candidates/java/1.7
    ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin ~/.jenv/candidates/java/1.8
    

    4.You are all set

    switch command:

    jenv use java 1.8

    set default:

    jenv default java 1.7

    0 讨论(0)
  • 2020-11-22 16:27

    tl;dr

    Add the line:

    export JAVA_HOME='/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home'

    to the file

    ~/.bash_profile

    (replace jdk1.8.0_144.jdk with your downloaded version)

    then source ~/.bash_profile

    0 讨论(0)
  • 2020-11-22 16:27

    Four easy steps using terminal for people who uses the default process.. :)

    1. echo $JAVA_HOME gives you current java home. For eg: /Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk/Contents/Home/

    2. cd /Library/Java/JavaVirtualMachines/ will take you to the folder where u normally install jdks (It might be different for your machines)

    3. ls shows you available folders (normally it will have the version numbers, for eg: jdk1.8.0_191.jdk openjdk-11.0.2.jdk)
    4. export JAVA_HOME='/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home' will change the java home..
    0 讨论(0)
提交回复
热议问题