kromer
kromer

Reputation: 91

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.

Upvotes: 9

Views: 12380

Answers (4)

hansvomkreuz
hansvomkreuz

Reputation: 11

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.

Upvotes: 1

taotao
taotao

Reputation: 857

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

Upvotes: 6

I've tried several solutions, downloading several sdk but Android Studio didn't recognize them as valid sdks.

Finally, the workaround that worked for me was:

  1. Delete Android Studio.app and Android Studio preferences (~/Library/Preferences/AndroidStuido).
  2. Rename /usr/libexec/java_home to java_home.bak.
  3. Install again Android Stuido.
  4. When Android Studio prompts for a valid Java SDK, follow link provided by Android Studio and download that java installation.
  5. After installation, push detect button on Android Studio, and run.

Upvotes: 0

Ian Roberts
Ian Roberts

Reputation: 122394

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.

Upvotes: 2

Related Questions