3

I've downloaded and installed Java JDK 8u45 for OS X 10.10.1 and after the installation has completed (successfully), java -version produces the following:

Unable to locate a Java Runtime to invoke.

Is this an installation bug with this particular version, or have I forgotten to do something?

enter image description here

me@my-laptop$ /usr/libexec/java_home -V
Matching Java Virtual Machines (0):

Default Java Virtual Machines (1):
    1.8.0_45, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
7
  • 1
    Do you have a $JAVA_HOME environment variable set by any chance? Does echo $JAVA_HOME return anything? Commented May 2, 2015 at 14:46
  • Well that's interesting: $JAVA_HOME is /usr/lib/jvm/java-7-oracle. I just bought this mac the other day, java is one of the first things I tried to install. When I initially ran java -version it told me it needed to be installed.
    – RTF
    Commented May 2, 2015 at 14:48
  • 1
    Bingo! Hopefully. :) Find where that is set and remove it. It should be something like export JAVA_HOME=/usr/lib/jvm/java-7-oracle in a file something like .profile or .bashrc or something along that line in /Users/YOURUSERNAME. Commented May 2, 2015 at 14:52
  • Ahh... I'm coming from Ubuntu, and I copied over my .bashrc file exactly as is :o I'll have to go over it with a fine-tooth comb. Thanks buddy !
    – RTF
    Commented May 2, 2015 at 14:55
  • Have you taken that line out? Is that Java working for you now? Commented May 2, 2015 at 15:35

1 Answer 1

2

That error means Java can't work out which runtime to use. There can be a few reasons for this.

I've had this error in the past because I had more than one copy of Java installed, and none were selected for use in Java Control Panel.

  • Open System Preferences and click on the Java icon this should launch the "Java Control Panel".
  • Then select the Java tab and click "View...", this should bring up the "Java Runtime Environment Settings" window.
  • My guess is that you'll find more than one instance of Java listed here. Tick the box beside the one you want to use and click OK.

This is from a much older version with a different layout but it should look something like this. Multiple copies listed with tick boxes to tell the system which you want to use.

Example of Java Preferences window

Another way to check which runtimes you have installed is with the /usr/libexec/java_home -V command. Ideally it should return something like the following.

Matching Java Virtual Machines (1):
    1.8.0_45, x86_64:   "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

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

Failing that you can check whether you have a $JAVA_HOME environment variable set with echo $JAVA_HOME. There is a lot of advice online saying you should set this variable but if you do that then I believe it ignores the settings in Java Control Panel.

7
  • It looks like just the one installation, as far as I can tell. Question is updated with screenshot...
    – RTF
    Commented May 2, 2015 at 14:28
  • @RTF What happens if you try /usr/bin/java -version? Commented May 2, 2015 at 14:32
  • Same error message "unable to locate..."
    – RTF
    Commented May 2, 2015 at 14:33
  • @RTF And if you try /usr/libexec/java_home -V? Commented May 2, 2015 at 14:34
  • @AlistairMcMillan you answer got accepted and the OP was very cooperative in Q&A, be a good citizen and give the OP some points for that.
    – Ruskes
    Commented May 2, 2015 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .