Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS X Yosemite not finding Java 8 runtime

I installed Java 8 SDK (with update 25 for JRE) from the Oracle Java site using the instructions on this page

http://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html

and put the following line in my ~/.bash_profile

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

but when I try to compile or run a Java program in Bash I get the following message

No Java runtime present, requesting install.

and this window

I ran /usr/libexec/java_home to check:

$ /usr/libexec/java_home
Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.

But the JRE is in

/System/Library/Frameworks/JavaVM.framework/Versions/Current

and the JRE location in System Preferences is pointing to

/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin

I don't know what the problem is here, but usr/bin/javac and /usr/bin/java are not able to find the correct JVM location in /System/Library/Frameworks/JavaVM.framework/Versions/Current.

like image 847
kromer Avatar asked Jan 09 '15 14:01

kromer


People also ask

Why does my Mac say unable to locate a Java Runtime?

The message “Unable to load Java Runtime Environment” means that the Mac computer cannot load JRE, either because it is out of date or (more usually) because it has not yet been downloaded and installed. It can also happen after the computer OS X has been updated, e.g. to 10.14 Mojave from 10.13 Maverick.

Where is JDK 8 installed Mac?

In macOS, the JDK installation path is /Library/Java/JavaVirtualMachines/jdk-10. jdk/Contents/Home . The root directory of the JDK software installation.


4 Answers

I have encountered the same problem , i think you should install JDK but not JRE

like image 99
taotao Avatar answered Oct 05 '22 20:10

taotao


You need to add some backticks:

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

The /usr/libexec/java_home command outputs the right value for JAVA_HOME on its standard output, you need to use backticks to capture that value so you can store it in the variable.

But the JRE is in /System/Library/Frameworks/JavaVM.framework/Versions/Current

No, it isn't. The Oracle JRE installs itself under /Library/Internet Plug-Ins, the Oracle JDK installs under /Library/Java/JavaVirtualMachines. The binaries under /usr/bin and /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands are stubs that delegate to whichever JDK your JAVA_HOME variable points to.

like image 24
Ian Roberts Avatar answered Oct 05 '22 21:10

Ian Roberts


Here's how I solved my problem on my mac

  1. Check from RStudio if Java_HOME has been setup properly by running Sys.getenv("JAVA_HOME") in the console. If it returns blank, you need to set it up properly

  2. Check whether you have Java SDK installed

    • Open terminal and check if you have Java SDK installed
    • Run the /usr/libexec/java_home -vcommand. This will show you the library where you Java SDK is installed.
  3. If you don't have Java SDK installed yet, result from command above is blank, or the version is not up-to-date, download here and install the latest version.

  4. Copy the library shown in step 2. On my mac, it shows: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home

  5. Back on your RStudio console, set the JAVA_HOME Sys.setenv(JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home")

After doing the steps above, h2o.init() ran without hitch.

Please carefully note @Ian Robert's point on JRE vs JDK distinction. We need JDK to make h2o run.

like image 37
Juan dela Cruz Avatar answered Oct 05 '22 18:10

Juan dela Cruz


Here's how I solved my problem on my mac

  1. Check from RStudio if Java_HOME has been setup properly by running Sys.getenv("JAVA_HOME") in the console. If it returns blank, you need to set it up properly

  2. Check whether you have Java SDK installed

    • Open terminal and check if you have Java SDK installed
    • Run the /usr/libexec/java_home -vcommand. This will show you the library where you Java SDK is installed.
  3. If you don't have Java SDK installed yet, result from command above is blank, or the version is not up-to-date, download here and install the latest version.

  4. Copy the library shown in step 2. On my mac, it shows: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home

  5. Back on your RStudio console, set the JAVA_HOME Sys.setenv(JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home")

After doing the steps above, h2o.init() ran without hitch.

Please carefully note @Ian Robert's point on JRE vs JDK distinction. We need JDK to make h2o run.

like image 45
hansvomkreuz Avatar answered Oct 05 '22 22:10

hansvomkreuz