8 minutes

How to Install Java for MacOS and Windows?

By Nilanchala @nilan, On Dec 04, 2023 Java 2.24K Views

You have two choices when it comes to installing Java. You either use the Oracle JDK or OpenJDK. Oracle JDK offers all the features of Open JDK, plus some proprietary features and commercial support from Oracle.

Open JDK is the open source version of Java and it is free to use for both personal and commercial projects.

There are many different distributions of OpenJDK available, some of the popular distributions are Amazon Corretto, Microsoft JDK, Azul Zulu, and Red Hat OpenJDK.

In this article, we show you how to install Java on Mac using SDKMan and Homebrew and using windows installer.

Install Java Using SDKMan

SDKMan is a command line utility used for managing multiple versions of SDKs. This works for MacOS and Linux, Windows WSL.  SDKMan simplifies the installation, management, and switching between different versions of Java SDK effortlessly.

To get the list of available java SDK's using SDKMan, use

sdk list java

This will return a list of all available Java versions

You can filter a specific Java version using `grep` command.  

sdk list java | grep 17

Now to install a specific version, you need to use the distribution identifier

sdk install java 21-amzn

To check the list of installed Java versions

sdk list java | grep installed

Use specific versions of Java

sdk use java 21-amzn

Install Java in Windows OS

For instructions on how to install using the graphical PKG and MSI installers, or through package managers WinGetHomebrewapt, and yum, see the Install page.

To ensure that Java is installed correctly, open a Command Prompt or PowerShell window and enter the following command.

java -version

Install Java using Homebrew

  • Type brew search openjdk to find all available Java-related formulas.
$ brew search openjdk
==> Formulae
openjdk ✔           openjdk@11          openjdk@17 ✔        openjdk@8

==> Casks
adoptopenjdk       homebrew/cask-versions/adoptopenjdk8
microsoft-openjdk  homebrew/cask-versions/microsoft-openjdk11

To show the formula details, you can use the brew info command. The Java formula always contains the latest OpenJDK version; at the time of writing, the latest is JDK 17.

The openjdk@17 formula contains the Java 17LTS version

$ brew info openjdk@17
==> openjdk@17: stable (bottled) [keg-only]
Development kit for the Java programming language
/usr/local/Cellar/openjdk@17/ (639 files, 305.6MB)
  Poured from bottle on 2023-09-25 at 00:00:57
From:[email protected]
License: GPL-2.0-only with Classpath-exception-2.0
==> Dependencies
Build: autoconf ✘
==> Requirements
Build: Xcode ✔
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk@17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk

openjdk@17 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have openjdk@17 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openjdk@17/bin:$PATH"' >> ~/.zshrc

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

==> Analytics
install: 30,649 (30 days), 82,462 (90 days), 154,946 (365 days)
install-on-request: 20,080 (30 days), 52,615 (90 days), 88,978 (365 days)
build-error: 65 (30 days)

Now install the Open JDK 17:

brew install openjdk@17
nilan avtar


I'm a blogger, educator and a full stack developer. Mainly focused on Java, Spring and Micro-service architecture. I love to learn, code, make and break things.