1

I a M1 macOS, I am trying to install Java 18-19, so I do as suggested in How to brew install java? :

brew install java

After many downloadings, I receive the following message:

Warning: openjdk 19.0.1 is already installed and up-to-date.
To reinstall 19.0.1, run:
  brew reinstall openjdk

So I do this reinstallation and everything seems OK.

I would think that Java (version 19.0.1) is already installed, but if I check it as suggested at How to brew install java? :

java --version

Then I get:

openjdk 11.0.18 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-11.0.18.10.1 (build 11.0.18+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.18.10.1 (build 11.0.18+10-LTS, mixed mode)

How can I solve this and get the right version?

It could be the case that the error is really simple, but I really do not know how to solve it. I referred to How to brew install java? because it seems it helped a lot of users. I also tried java -version shows earlier version but java 11 is already installed and java -version shows earlier version but java 11 is already installed, but for both of them (which have the same solution) zsh tells me the command does not exist.

(EDIT) Trying to reinstall openjdk

(base) name % brew reinstall openjdk
==> Fetching openjdk
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/19.0.1-1
Already downloaded: /Users/name/Library/Caches/Homebrew/downloads/c7246ceb366faabcf9dd032058533f2e54a55b52e0baf1e45630280826b0f013--openjdk-19.0.1-1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:8380eef4472205fdc0b3968c1241bfc616efaea90aef325198d767a74d2f78ee
Already downloaded: /Users/name/Library/Caches/Homebrew/downloads/f3ccacbd4108895428c5d98052e634e0bb296638d180f9fffe8018c6ef76823c--openjdk--19.0.1.monterey.bottle.1.tar.gz
==> Reinstalling openjdk 
==> Pouring openjdk--19.0.1.monterey.bottle.1.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"' >> ~/.zshrc

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

==> Summary
  /usr/local/Cellar/openjdk/19.0.1: 638 files, 318.6MB
==> Running `brew cleanup openjdk`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
Theo Deep
  • 666
  • 4
  • 15
  • 1
    Did you follow the steps `brew install` spits out in the terminal after installing openjdk? – MSpiller Jan 24 '23 at 16:38
  • I did that long time ago.. how can I know that? – Theo Deep Jan 24 '23 at 16:43
  • 1
    Thought you "just" did install openjdk... You could simple do a `brew reinstall openjdk` and follow the steps again. That should do no harm – MSpiller Jan 24 '23 at 16:43
  • Just did it, it seems correctly installed and no more steps were shown :( – Theo Deep Jan 24 '23 at 16:45
  • 1
    I just on my machine did a reinstall and it was printing the exact steps what to do. Even though my openjdk is correctly setup. This is THE line: `sudo ln -sfn $(brew --prefix)/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk` – MSpiller Jan 24 '23 at 16:46
  • I did not receive that message... I did the code you suggest and got: `ln: /Library/Java/JavaVirtualMachines/openjdk.jdk: No such file or directory`. Any idea? – Theo Deep Jan 24 '23 at 16:48
  • 1
    Not really, `/Library/Java/JavaVirtualMachines` does exist on every mac. Please execute `brew reinstall openjdk` and post the COMPLETE output (in the question) – MSpiller Jan 24 '23 at 16:53
  • I did not know that. Just done it (see EDIT). – Theo Deep Jan 24 '23 at 16:55
  • 1
    So just execute these steps. – MSpiller Jan 24 '23 at 16:56
  • Hi, I just executed the step `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`, but got the same error `ln: /Library/Java/JavaVirtualMachines/openjdk.jdk: No such file or directory`. Also performed `echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> ~/.zshrc ` and `export CPPFLAGS="-I/usr/local/opt/openjdk/include"` but got the same error. – Theo Deep Jan 24 '23 at 16:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/251371/discussion-between-m-spiller-and-theo-deep). – MSpiller Jan 24 '23 at 17:01
  • 1
    This means that you **also** have Java 11 installed in some way (probably not via brew), and the order on the PATH (or for example a symlink), causes it to use choose Java 11 instead of Java 19. – Mark Rotteveel Jan 24 '23 at 17:33
  • Hm.. and do you know how can I change this? – Theo Deep Jan 24 '23 at 17:45

0 Answers0