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

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

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

28条回答
  •  孤城傲影
    2020-11-22 16:05

    Use jenv, it is like a Java environment manager. It is super easy to use and clean

    For Mac, follow the steps:

    brew install jenv
    
    git clone https://github.com/gcuisinier/jenv.git ~/.jenv
    

    Installation: If you are using bash follow these steps:

    $ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
    
    echo 'eval "$(jenv init -)"' >> ~/.bash_profile
    
    $ exec $SHELL -l
    

    Add desired versions of JVM to jenv:

    jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    
    jenv add /System/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home
    

    Check the installed versions:

    jenv versions
    

    Set the Java version you want to use by:

    jenv global oracle64-1.6.0
    

提交回复
热议问题