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`).