Brew: JDK 8 is installed but getting: 'Java is required to install this formula.JavaRequirement unsatisfied!'

Created on 28 Mar 2017  路  10Comments  路  Source: Homebrew/brew

I tried updating brew and upgrading all my outdated formula today, but got the 'Java 1.7+ is required to install this formula.JavaRequirement unsatisfied!' error.

Additionally I get the same error when trying to install ant, except the message is for java 1.8+. I originally had ant installed but it failed to upgrade in the same manner as the other formula's above. I tried to uninstall and reinstall ant and got the same error.

I searched for any other issues that may be related, but only found an old issue where they were pointing at a jre instead of a jdk (https://github.com/Homebrew/legacy-homebrew/issues/50035).

Here is the gist of the output of all my steps I took trying to debug this:

https://gist.github.com/nickg415/1c7a1c8bfe28d75320960e7a7f53c265

Most helpful comment

For now I'd suggest unsetting JAVA_TOOL_OPTIONS. The longer-term solution is enabling https://github.com/Homebrew/brew/issues/932 for everyone.

All 10 comments

Try to unset JAVA_HOME. Did you try rew cask reinstall java?

Just tried that now, but was unsuccessful. Updated the gist (new starts at line 145).

Can I see your brew config and brew doctor output with JAVA_HOME unset? Thanks!

CC @rwhogg in case you have any ideas here as you worked here recently.

Updated the gist with these (starts at line 265)

@nickg415 Just made a new tag. Can you try to brew update once more and see if it fixes anything? If not: I think I'm stumped here 馃槶

@nickg415 if that doesn't work, feel free to join the #machomebrew IRC channel and I can try debugging it with you interactively.

(Alternatively, if you're not comfortable with IRC, you can try the following commands in brew irb and tell me what it gives:)

  • JavaRequirement.new(%w[1.7+]).send("possible_javas")
  • JavaRequirement.new(%w[1.7+]).send("preferred_java")
  • JavaRequirement.new(%w[1.7+]).send("java_home_cmd")
  • JavaRequirement.new(%w[1.7+]).send("satisfied?")

The gist of the issue is that if $JAVA_TOOL_OPTIONS is set, it inserts extra output into java -version. $JAVA_TOOL_OPTIONS included the string "1.1" in it, so JavaRequirement mistakenly thought it was Java version 1.1 instead of 1.8.

I'm not immediately sure of the appropriate fix for this, but for now a workaround is to unset $JAVA_TOOL_OPTIONS.

(Side note: I should really open a PR to add a newline to the output of the failure message for JavaRequirement.)

@rwhogg Updated the gist with our chat in IRC.

also, didn't notice you left IRC before I posted this:

so is there any actionable thing that could be done to improve that? or not worth the effort at this time? I'm not really familiar with the inner workings of brew (obviously), but if you point me the right direction (and if I can find the time), I may be willing to contribute
nickg415
definitely agree that some check should be put into brew doctor
nickg415
thoughts on maybe some regex or parsing improvement to ignore the output of JAVA_TOOL_OPTIONS?

For now I'd suggest unsetting JAVA_TOOL_OPTIONS. The longer-term solution is enabling https://github.com/Homebrew/brew/issues/932 for everyone.

I just had this same issue and both my $JAVA_HOME and $JAVA_TOOL_OPTIONS were unset at the time. I had Java 1.8, 9, and 10 installed, and setting my $JAVA_HOME var to either of those did not solve the issue. Running brew irb with the commands suggested by @rwhogg above produced the following:

$ brew irb
==> Interactive Homebrew Shell
Example commands available with: brew irb --examples

irb(main):001:0> JavaRequirement.new(%w[1.7+]).send("possible_javas")
=> [#<Pathname:/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/java>]

irb(main):002:0> JavaRequirement.new(%w[1.7+]).send("preferred_java")
=> nil

irb(main):003:0> JavaRequirement.new(%w[1.7+]).send("java_home_cmd")
=> #<Pathname:/Library/Java/JavaVirtualMachines/jdk-10.jdk/Contents/Home/bin/java>

irb(main):004:0> JavaRequirement.new(%w[1.7+]).send("satisfied?")
=> false

In the end, I was able to solve the issue by setting $JAVA_HOME to 1.8 as follows:

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

paanvaannd picture paanvaannd  路  4Comments

fxcoudert picture fxcoudert  路  3Comments

vitahlin picture vitahlin  路  4Comments

VagelisD picture VagelisD  路  3Comments

MikeMcQuaid picture MikeMcQuaid  路  3Comments