java's path still /usr/bin/java after brew cask install java
Asked Answered
F

3

26

I installed java with homebrew, using the command brew cask install java.

After successfully installing, I typed which java, and the path showed to be /usr/bin/java

When I typed brew cask info java, this showed up:

java: 1.8.0_102-b14 Java Standard Edition Development Kit

/usr/local/Caskroom/java/1.8.0_102-b14 (227.5M) https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb Contents JDK 8 Update 102.pkg (pkg) Caveats This Cask makes minor modifications to the JRE to prevent issues with packaged applications, as discussed here: If your Java application still asks for JRE installation, you might need to reboot or logout/login.

Installing this Cask means you have AGREED to the Oracle Binary Code License Agreement for Java SE at

Did I forget to link something?

Fa answered 12/8, 2016 at 15:19 Comment(5)
I have java 1.8.0_102 installed from brew cask, and if I do which java I also get /usr/bin/java. So that’s not an indication of a problem. /usr/bin/java is just a symlink to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java which I guess is some indirection thing that finds the right java binary. Anyway, what do you actually get if you run java -version? In my environment, even though which java gives me /usr/bin/java, java -version gives me java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) (the cask version) as expected.Hyde
I get this:java version "1.8.0_102" Java(TM) SE Runtime Environment (build 1.8.0_102-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)Fa
So that’s what you want to see, right? Since that means when you just type java it’s using the version you installed from homebrew—and it means the fact that which java tells you /usr/bin/java is not a problem (in fact that’s expected). In other words, you already have everything working as it should be, and there’s nothing more you need to do (e.g., you don’t need to link anything more).Hyde
mkyong.com/java/how-to-install-java-on-mac-osxOlney
What exactly is the question here? "Did I forget to link something", in order to do what? If you didn't intend to link something, sounds like you didn't forget anything :)Brakpan
W
37

/usr/bin/java is a symlink.

To see where it points, type ls -la /usr/bin/java

brew cask is installing into /Library/Java/JavaVirtualMachines/jdk1.8.0_something.jdk/Contents/Home

If the previous command ls -la is matching this, you are good.

If not, it means that you previously had another java installation. In this case, you may want to use a tool like jenv to switch between your multiple installs.

Wisner answered 16/1, 2018 at 7:3 Comment(2)
This isn't always true. brew install. (without cask) wont do thatCaracaraballo
run brew --prefix java, so you can find the correct java location. In my case, using wsl, java has this location: /home/linuxbrew/.linuxbrew/opt/openjdkErvin
L
5

To add to @djangofan .. when I did a brew reinstall, I noticed the following message:

==> Pouring openjdk--17.0.1_1.big_sur.bottle.tar.gz
==> Caveats
For the system Java wrappers to find this JDK, symlink it with

  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into
/usr/local, because macOS provides similar software and
installing this software in parallel can cause all kinds of
trouble.

If you need to have openjdk first in your PATH, run:
 echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/johndoe/.bash_profile

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"

To his point, I did not install via cask. I assume that when you did the install you got a similar message that you simply did not notice.

Lenna answered 10/1, 2022 at 18:6 Comment(2)
I went too fast while installing and missed those messages. Thanks for posting!Danidania
If you need to see this message again, just it the following line in your Terminal: brew info java The important bit there is the following: echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc That will make sure you use the latest brewed java version every time you open a new Terminal from now (in my example, I use zsh so in .zshrcfile it goes)Sine
N
0

Asking everyone landing to this Q&A to install jenv when their problem has nothing to do with jenv is off-topic.

While I am a big fan of jenv, this isn't the way IMHO, and it will lead everyone to waste time, just like it led me.

So, In order to fix /usr/bin/java pointing to the wrong JDK/JAVA, this is what you have to do, after you've even set up JAVA_HOME and it still ain't working:

# sudo ln -sfn source target
sudo ln -sfn /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

Where:

  1. /opt/homebrew/opt/openjdk@17/libexec/openjdk.jdk is your source
    ie. the path where your JAVA, yet most likely JDK is installed
    • To find it automatically, run brew --prefix java
  2. /Library/Java/JavaVirtualMachines/openjdk-17.jdk is your target
    ie. the path which you want your /usr/bin/java to point towards.
Narrative answered 29/7, 2024 at 13:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.