Vibhore Sagar
Vibhore Sagar

Reputation: 107

Brew installed Java unable to symlink with System java folder

I installed Java11 using Homebrew running the command on my M1 mbp

brew search java
brew install java11

Which installed the java version. Then when I run

brew info java

I get this

openjdk: stable 17.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✔
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

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

==> Analytics
install: 229,799 (30 days), 652,569 (90 days), 2,040,179 (365 days)
install-on-request: 64,996 (30 days), 187,761 (90 days), 591,813 (365 days)
build-error: 5,513 (30 days)

I ran the sudo command under Caveats but I don't know if it did anything. When I run

Java --version

I get this

The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.

I don't understand why this is happening. I had Java up and running before but I had to format and install a fresh copy of the OS and now when I'm trying to install Java again Im running into this problem. Im assuming the symlink between Homebrew java install location isn't linking with the system java location, but I could be wrong.

Upvotes: 2

Views: 7436

Answers (2)

Calpurnio Pisone
Calpurnio Pisone

Reputation: 57

For me installing temurin17 via brew solved, has already suggested here: https://stackoverflow.com/a/74260169/8520417

Upvotes: 0

Y Melo
Y Melo

Reputation: 423

I was having the same problem, but when I ran brew info java it gave me a few steps to run:

sudo ln -sfn /Users/${whoami}/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

export PATH="/home/${whoami}/homebrew/opt/openjdk/bin:$PATH"

java -version 
# This should work
# To make the export permanent
echo 'export PATH="/Users/${whoami}/homebrew/opt/openjdk/bin:$PATH"' >> ~/.zshrc 

Assuming that ${whoami} (Your username is the same as your home folder). Otherwise, replace the variable with your actual folder name.

Also, it looks like you want java11, you probably have that under ~/homebrew/opt/

You can search it:

find ~/homebrew/ -name '*openjdk*'

You will find a file like openjdk@11 which for me was in ~/homebrew/opt/openjdk@11 in this case, you can export:

export PATH="/home/${whoami}/homebrew/opt/openjdk@11/bin:$PATH"

instead of

export PATH="/home/${whoami}/homebrew/opt/openjdk/bin:$PATH"

Upvotes: 2

Related Questions