将mac jdk版本设置为1.8

时间:2021-03-27 00:24:45

I have searched several ways to change JDK version on mac.

我已经搜索了几种在Mac上更改JDK版本的方法。

$/usr/libexec/java_home

And I got

而我得到了

/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

I tried

我试过了

$export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

also tried

也试过了

/usr/libexec/java_home 1.8.0_31 --exec javac -version

then I run

然后我跑了

$echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home

then I re-check java -version

然后我重新检查java -version

$java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

How I can really change java -version on my mac.

我怎么能真正改变我的mac上的java -version。

1 个解决方案

#1


21  

To set Java to 1.8 for your shell environment, put this in your ~/.bash_profile:

要为您的shell环境将Java设置为1.8,请将其放在〜/ .bash_profile中:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

#1


21  

To set Java to 1.8 for your shell environment, put this in your ~/.bash_profile:

要为您的shell环境将Java设置为1.8,请将其放在〜/ .bash_profile中:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`