How to Install Java on macOS?
The Java Development Kit (JDK) is an essential tool for developers working with Java. It provides the necessary tools and libraries to build, compile, and run Java applications, making it a cornerstone for efficient and effective Java development. Without the JDK, writing and testing Java programs would be far more complex, as it includes critical components like the Java compiler, runtime environment, and standard libraries.
Now, let’s talk about the latest and greatest: Java 23! This cutting-edge version brings a treasure trove of advanced features and optimizations, giving developers the tools they need to create modern, efficient applications while maintaining compatibility with older versions. Alongside Java 21 and 17, Java 23 is a long-term support (LTS) version, ensuring reliability and robust updates for years to come.
Note: Java 23 is more than an update; it’s built for long-term support. Oracle will back it with premier support until September 2028 and extended support until September 2031. Whether you’re working on large-scale projects or personal experiments, this version ensures stability and reliable updates for years.
Methods to Install JDK in Mac
There are two ways you can install Java on a Mac machine, and in this guide, we are going to describe each method one by one. So, explore the methods and choose which one eases you the most.
- Direct Installation via Installer
- Using a terminal via Homebrew
Method 1: Install Java in macOS via Installer
- Here we will be discussing the first method where java can be downloaded from Oracle's official Website and can be installed with the help of the following steps:
Step 1: Download JDK form Official Site
- Go to the Oracle official site to download Java 23 by clicking on the download option as highlighted in the below media over where you need to download '.dmg' one and carry on with the download procedure.
Tip: You can also opt to download the x64 compressed archive and then extract it to your Mac.But in mac while downloading any application it is suggested to download complete files instead of compressed files due to internal constraints of macOS ocosystem.
- Open the DMG file -> double click the JDK package to downloaded in the previous step to start installing Oracle JDK 23 on your Mac. It will install the DMG disk and presents the installer as shown in Figure. Go through the updated License Agreement of Oracle JDK.

Step 2: Choose Destination
- Click the Continue button -> select destination -> install -> Enter your password to give permission to install java 23.

Note: You may change the installation location by clicking the Go Back Button. It didn’t allow me to change the installation location on Big Sur on later macOS.
Step 3: Click on the Close Button
- Once the installation is completed you will see the pop up of installation succeeded.

Now unmount the DMG image as shown in Fig by right-clicking it basically we are deleting the setup just unlikely we do in Windows.
Step 4: Check the Java Version
To confirm the installation, we can check the JDK version, as shown in the picture below. That's all about installing Oracle JDK 23 on macOS.
java -version

How to set/change the Path of Java on macOS?
We need to be super attentive and careful as it is very useful in understanding java on any machine. Now we need to change the path of Java on Mac, for which certain steps are to be followed these steps :
Step 1: Open Terminal -> type: “which java”. It should show something like /usr/bin/java.

JAVA_HOME is the full path of the directory that contains a sub-directory named 'bin' which includes the JavaJava. For Mac OSX – it is /Library/Java/Home
Step 2: Set JAVA_HOME using this command in Terminal, you no longer need to remember just stress over it and go on
export JAVA_HOME=/Library/Java/Home
Step 3: To confirm the path, write the following command
echo $JAVA_HOME

Step 4: You should now be able to run your application
Note: This only sets JAVA_HOME for this session. If you want it to be permanent, you'll have to add the command to your ~/.zshenv or ~/.zshrc file as on macOS 10.15 Catalina, and later, the zsh is the default Terminal shell. To accomplish this instead follow these instructions:
Step 5: Open terminal and type:
nano ~/.zshenv

One can also use any other terminal command line text editors of your choice
Step 6: Adding this to the end of the ~/.zshenv file
export JAVA_HOME=$(/usr/libexec/java_home)

Step 7: Save and exit nano (ctrl-x, option-a, enter)
Step 8: Source the file and print the $JAVA_HOME.
source ~/.zshenv
echo $JAVA_HOME
If we do see the below command then we have successfully set your JAVA_HOME environment variable
/Library/Java/JavaVirtualMachines/jdk-23.jdk/Contents/Home
Methods 2: Install JDK in macOS via Homebrew
In this section we will guide how to install Java in Mac machine using Homebrew package manager.
Step 1: Update Homebrew
- Ensure your Homebrew is up-to-date by running:
brew update
Step 2: Check for JDK Versions
- Check if JDK 23 is available through Homebrew:
brew search openjdk
Look for openjdk@23 in the list. If it’s not available, you may need to check Homebrew’s latest updates or use a tap for additional versions.
Step 3: Install JDK 23
- If JDK 23 is listed, install it using:
brew install openjdk@23
Step 4: Configure Environment Variables
- To make JDK 23 the default version, add its path to your shell profile:
- Find the installation path:
/usr/libexec/java_home -v 23
- Add the path to your shell configuration file (e.g., ~/.zshrc for Zsh or ~/.bash_profile for Bash):
echo 'export JAVA_HOME=$(/usr/libexec/java_home -v 23)' >> ~/.zshrc
echo 'export PATH="$JAVA_HOME/bin:$PATH"' >> ~/.zshrc
Reload the shell configuration:
source ~/.zshrc
Step 5: Verify the Installation
- Check if JDK 23 is installed and set up correctly:
java -version
Conclusion
Installing JDK on macOS can be accomplished using two primary methods: through Homebrew or by downloading it directly from the Oracle website. The Homebrew method is ideal for those familiar with command-line tools, offering a quick and automated process to manage Java versions. On the other hand, downloading JDK from Oracle provides more control over specific versions and official updates, suitable for those who prefer a graphical installation process. Both methods are effective, and you can choose the one that best fits your workflow and comfort level.