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

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

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

28条回答
  •  长情又很酷
    2020-11-22 16:14

    Based on @markhellewell answer I created a couple of alias functions that will do it for you. Just add these to your shell startup file

    #list available jdks
    alias jdks="/usr/libexec/java_home -V"
    # jdk version switching - e.g. `jdk 6` will switch to version 1.6
    function jdk() { 
      echo "Switching java version"; 
      export JAVA_HOME=`/usr/libexec/java_home -v 1.$1`; 
      java -version; 
    }
    

    https://gist.github.com/Noyabronok/0a90e1f3c52d1aaa941013d3caa8d0e4

提交回复
热议问题