How to install openjdk with brew


(freshghost) #1

now,how to install openjdk with brew .


(Mike McQuaid) #2

brew cask install java


(Stefan Crain) #3

brew cask install java does not install openjdk version of java but oracle java.

$ brew cask info java
java: 9,181
https://www.oracle.com/technetwork/java/javase/downloads/jdk9-downloads-3848520.html
Not installed
From: https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb
==> Name
Java Standard Edition Development Kit
==> Artifacts
JDK 9.pkg (Pkg)
==> Caveats
This Cask makes minor modifications to the JRE to prevent issues with
packaged applications, as discussed here:

  https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361

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

  https://www.oracle.com/technetwork/java/javase/terms/license/index.html

Does anyone have a further lead on this?


(Joshua McKinney) #4

There is no openjdk Formula or Cask. A quick browse of the openjdk website didn’t particularly promise any easy obvious ways to install for macOs.

Your best bet for this is to work with the upstream developers on working out what’s built / available for macOS and help them to create a formula / cask (depending on whether it’s delivered predominantly as source / CLI only vs binary / CLI + GUI stuff like JavaSE).


(George Adams) #5

I would recommend checking out https://github.com/AdoptOpenJDK/homebrew-openjdk where you can go and grab prebuilt openjdk binaries for macOS!

It’s just a case of using:

brew tap AdoptOpenJDK/openjdk
brew install <version>

Where version is:

  • adoptopenjdk-openjdk8
  • adoptopenjdk-openjdk9
  • adoptopenjdk-openjdk10

(Luke Dutton) #6

Thank you so much for this!
Where is the openjdk placed when you install it this way?
When you install the oracle jdk, it is placed in the java virtual machines folder.


(Jeno Dk) #7

@Jolley71717

 ~ $ java -version
openjdk version "1.8.0-adoptopenjdk"
OpenJDK Runtime Environment (build 1.8.0-adoptopenjdk-jenkins_2018_05_19_02_01-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)
λ ~ $ ls -l `which java`
lrwxr-xr-x  1 jeno  admin    53B Oct  5 10:37 /usr/local/bin/java@ -> ../Cellar/adoptopenjdk-openjdk8/jdk8u172-b11/bin/java

Allthough I do have something strange, my $JAVA_HOME still points to a previously installed JDK:

λ ~ $ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home

Anyone knows a nice way to switch in between openJDK’s (can be different versions as well) and oracle JDK’s?
For just oracle JDK’s I was planning to use https://stackoverflow.com/a/47699905 , would this also work for openJDK’s?


(Jeno Dk) #8

My $JAVA_HOME I just set manually or let jenv do it

Followed this:
https://gist.githubusercontent.com/chaines27/7f9a91237e79e6b4b28899b96d74986f/raw/96348a1014aaf4b6153895b2010324d3eb4b14f5/homebrew-openjdk-configuration

Open github issue:


(George Adams) #9

For people having issues witht the AdoptOpenJDK brew taps ands JAVA_HOME issues. Please check out the brand new brew cask. Simply run brew cask install adoptopenjdk. This currently only works for OpenJDK11 but we will be converting our previous versions over to casks soon!


#10

As of 9 Oct 2018 I see openJDK when I search for java.

brew cask info java
java: 11,28
https://jdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rb
==> Name
OpenJDK
==> Artifacts

Or am I reading that wrong?


(Sean Molenaar) #11

You’re reading it correctly but openjdk is now the “official” implementation unless you paid for it. https://blogs.oracle.com/java-platform-group/oracle-jdk-releases-for-java-11-and-later


#12

Is there a difference between the openjdk provided by the cask java and the cask adoptopenjdk?


(Sean Molenaar) #13

AdoptJDK is https://adoptopenjdk.net/
OpenJDK is https://jdk.java.net/


#14

But are they the same source or are they competing implementations of the JDK? I haven’t followed the java world very closely so I’m not sure if there was a fork or something.


(Sean Molenaar) #15

Should be the same source but packaged differently. You can check the adoptopenjdk github to see if they do anything special to the build


(Thug Els) #16

Trying to install via brew cask install adoptopenjdk. The install starts, but as brew writes files to /Library/Java/JavaVirtualMachines/jdk-11+28, it asks for admin password for every. single. file. I’ve also tried running w/ sudo to no avail.

Is there a way around this?


(Andrew Janke) #17

FYI, the Cask definitions have changed as of https://github.com/Homebrew/homebrew-cask/pull/52556.

Now, brew cask install java does install OpenJDK; the Oracle JDK is now in a separate oracle-jdk cask.


(Andrew Janke) #18

Which Java 11 JDK are the CI servers using now? The Oracle JDK is a commercial-only license as of Java 11. We might want to be running OpenJDK, especially if that’s the default one that brew cask install java is giving users now.


(Thug Els) #19

Tried install with brew cask install java. Still getting asked for password for every file it tries to write. Is no one else encountering this problem?


(Ted) #20
tvinke@localhost ~ $ brew cask install java
Updating Homebrew...
==> Satisfying dependencies
==> Downloading https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_os
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'java'.
==> Installing Cask java
Password:
🍺  java was successfully installed!
tvinke@localhost ~ $

No problem here!