OK, it’s 2021 and you got new Macs. Or maybe you just finished upgrading your macOS to Catalina or Big Sur and found there is no Java anymore. This article might help you with that.
As widely known, Oracle announced that the Oracle JDK 8 builds released after JAN 2019 will not be free for commercial use. Since OS X 10.7 Java is not (pre-)installed anymore. Well, I’m not a fan of Java myself (i stop using it after Java 1.6 i guess). But since I’m also tinkering with Android (and Kafka), I have no choice but put Java in my dev machines.
Instead using Oracle’s, I will use OpenJDK.
There are several ways to install OpenJDK to your Mac.
- Simply install the prebuilt OpenJDK binary.
- Install via homebrew
- Compile the source codes your self :P
Option #1.
Adoptium is one of the best places to find prebuilt OpenJDK binaries. And as i write this article the lates LTS version is OpenJDK 11.0.12+7.
For you information, Adoptium previously was known as AdoptOpenJDK. The project’s goal was for providing the Java community with rock-solid runtimes and associated tools that can be used free of charge, without usage restrictions on a wide range of platforms. Later on, on June 2020 (cmiiw) AdoptOpenJDK moved to Eclipse Foundation and change the brand to Eclipse Adoptium Project.
- Click on the OpenJDK installer as shown above. The installation window will appear and you just need to follow the instructions.
- After finish, you need to verify the installation using command
java -version
It should be returning the information as shown below.
- Almost done. Your Java base installation directory will be located in
/Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
and that should be the value of your JAVA_HOME environment variable. Don’t forget to put it in your~/.zshrc
or~/.bash_profile
file depending on whatever shell you’re using.
That’s it. Done.
Option #2
This is the most convenient way -for me- to install tools within macOS, using homebrew. From your terminal, you can use the following commands.
For installing the latest LTS version
$ brew install --cask temurin
Install specific version
$ brew tap homebrew/cask-versions
$ brew install --cask temurin8
$ brew install --cask temurin11
Uninstall specific version$ brew uninstall --cask temurin