Search code examples
javamacosnativescriptjavac

Choose updated Java SDK in mac from available different version


I'm using mac machine for native-script development and while executing an program it thrown an java error that:

Javac version 1.6.0_65 is not supported. You have to install at least 1.8.0.

so I checked with available install version on developer machine & found two different version detail:

/usr/bin/java -version Showing 1.6.

while system preference -> java control panel -> update. showing V1.8

any suggestion why two version !! Am I missing something here?

Update1: Following help to understand how mac handling this: /usr/bin/java is machine default location, and /Library/Internet.. which is manage explicit.

sudo rm /usr/bin/java
sudo ln -s /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin

In my case I update default one with downloaded from internet.

Reference link Link1, Link2


Solution

  • You should use /usr/libexec/java_home instead

    > /usr/libexec/java_home
    /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
    

    you can use it to set JAVA_HOME

    export JAVA_HOME=$(/usr/libexec/java_home)
    

    then, you can put this one inside ~/.profile so you have always JAVA_HOME set to most recent release.