2

Wanted to install openjdk 16 on MacOS (macOS Big Sur 11.0.1; Apple M1). All went well but the versions showing aren't matching. Shows OpenJDK 17 but the path is /opt/homebrew/Cellar/openjdk/16.0.1/. Not sure if I have openjdk 16 or 17?

Steps:

1. $brew update
2. $brew install openjdk

But $java -version shows as 17

$ java -version
  openjdk version "17" 2021-09-14
  OpenJDK Runtime Environment Homebrew (build 17+0)
  OpenJDK 64-Bit Server VM Homebrew (build 17+0, mixed mode)

OR

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (1):
  17 (arm64) "Homebrew" - "OpenJDK 17"
    /opt/homebrew/Cellar/openjdk/16.0.1/libexec/openjdk.jdk/Contents/Home
       /opt/homebrew/Cellar/openjdk/16.0.1/libexec/openjdk.jdk/Contents/Home

The confusing part is brew info openjdk shows: This is a beta version of openjdk for Apple Silicon (openjdk 17 preview).

$ brew info openjdk
openjdk: stable 16.0.1 (bottled) [keg-only]
Development kit for the Java programming language https://openjdk.java.net/ /opt/homebrew/Cellar/openjdk/16.0.1 (618 files, 281.4MB)
Poured from bottle on 2021-05-31 at 23:05:51
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb License: GPL-2.0-only with Classpath-exception-2.0
...
This is a beta version of openjdk for Apple Silicon (openjdk 17 preview).
...

On digging more, part of the code for the Homebrew formula openjdk at https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk.rb is actually installing 17 but showing the version as 16.0.1 on purpose?

if Hardware::CPU.arm?   
  # Temporarily use a openjdk 17 preview on Apple Silicon   
  # (because it is better than nothing)    
  url "https://github.com/openjdk/jdk/archive/refs/tags/jdk-17+24.tar.gz"    
  sha256 "9d1ea3fc63ce860e55a9be77f670b18fa7b7e5c9773dca3c70042403e1ee285c"   
  version "16.0.1"

1 Answer 1

0

Re-posting the answer from discussion in Github with Homebrew.

Ref: https://github.com/Homebrew/discussions/discussions/1594#discussioncomment-816728

When you use command brew info openjdk , i.e., a non-versioned formula in brew will always be the latest version available from upstream. In this case that is 17 for ARM (as a preview) and 16 on x86.

$brew info openjdk
openjdk: stable 16.0.1 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk/16.0.1 (618 files, 281.4MB)
  Poured from bottle on 2021-05-31 at 23:05:51

On M1/ARM it actually installs version 17 but folders would be named as "16". Yes, this may be an issue, but this is how, brew is, as of now (June 2021).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.