简体   繁体   中英

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 .

我遇到了同样的问题,我认为你应该安装JDK而不是JRE

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.

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 -v command. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM