Install Java on macOS in 10 Minutes

Try this guide with our instant dedicated server for as low as 40 Euros

Install Java on Mac

Developed in 1995 by Sun Microsystems, Java is still a preferred development language (and toolkit) for building cross-platform projects. 

Project managers and developers opt for Java because of its Write Once, Run Anywhere (WORA) principle, which states that Java code may run on any platform that supports Java without the need for changes and recompilation. The Java Virtual Machine (JVM), which translates Java bytecode into machine code appropriate for each unique platform, delivers this capability.

In this short tutorial, we’ll discuss three ways of installing Java on macOS. Next, we’ll go through the path configuration, and finally we’ll round off with a look at how to uninstall Java from your macOS system. 

Table Of Contents

  1. How to install Java on macOS
    1. Prerequisites
    2. Method #1: Install Oracle JDK on macOS
    3. Method #2: Install OpenJDK on macOS
    4. Method #3: Install JRE on macOS
  2. How to Uninstall Java from macOS
  3. Conclusion
  4. FAQs

How to install Java on macOS

You can download and install various Java Development Kit (JDK) builds. Oracle contributes to developing and maintaining OpenJDK, an open-source version of the environment, and the original, closed-source Oracle JDK. The main distinction between the two is a commercial license.

This guide explains installing Oracle JDK and OpenJDK on macOS. 


For installing Java on macOS, you’ll need the following:

  • A system running macOS version 10.7.3 or later.
  • An account with administrative privileges.

Method #1: Install Oracle JDK on macOS

Follow these steps to download and install the Oracle JDK on a Mac.

  1. Go to the Java Downloads page on Oracle’s website.

java downloads on oracle

  1. Select the macOS tab and download the DMG package installer corresponding to your processor architecture.

We recommend selecting the appropriate installer to install ARM 64 on an M1 or M2 Mac. Alternatively, Mac users with Intel processors should select the x64 installation packages.

GMD package installer

  1. Open the DMG file to run the installer.
  2. Click Continue on the installer’s welcome screen.

GMD Installer welcome screen

  1. In the confirmation window that opens, click Install.

GMD standard installation

  1. Now, to begin the JDK installation using the package manager, enter the password for the administrator user to authenticate.
  2. Select Close after the installer has finished copying the files.

installation succeed

  1. Finally, verify that Oracle JDK has been successfully installed by printing the current Java version in the terminal. 

For this, launch the terminal and enter the following command:

~ java -version

java version

Method #2: Install OpenJDK on macOS

Using Homebrew to install OpenJDK is a great way of getting a Java environment on your Mac system. OpenJDK provides a similar set of capabilities and functionalities as Oracle’s commercial version. 

Developers use OpenJDK to set up an open-source, production-ready development environment for their projects.

These are the steps in the process of installing OpenJDK using Homebrew:

  1. Start by updating Homebrew by running the following command in the terminal:

~ brew update

  1. Next, run the following command to install OpenJDK:

~brew install openjdk@[version]

Replace [version] with the version you want to install. For instance, to install OpenJDK 21, run the following command:

~ brew install openjdk@21

brew install

Method #3: Install JRE on macOS 

The JDK package includes several components, including the Java Runtime Environment (JRE). However, if you just want JRE to run Java programs without requiring the full development package, we recommend this method of installing JRE in macOS.

download java for macOs

  • Click the download button to download the appropriate package.
  • Launch the installer to begin the installation process. You may need to provide an administrator password to authenticate.

license terms for java

  • At the end, click Close to finalize the process. 

successful installation

How to Configure macOS Java Path

After installing Java, especially when you opt to install OpenJDK with Homebrew, you need to add the appropriate path and export the JAVA_HOME variable. 

For this, follow these steps.

  1. Run the following command to add the JAVA_HOME variable to the .zshenv file and export it permanently:

~ echo "export JAVA_HOME=/opt/homebrew/opt/openjdk" >> ~/.zshenv

  1. Next, run the following command to include the Java installation in the PATH variable:

~ echo "export PATH="/opt/homebrew/opt/openjdk/bin:$PATH"" >> ~/.zshenv

  1. Use the following command to apply the changes to the present session:

~ source ~/.zshenv

  1. Verify the success by examining the Java version:

~ java -version

echo export java

How to Uninstall Java from macOS

When uninstalling Java from your macOS system, you’ll need administrator privileges. 

Here’re the steps of the process of uninstalling Java from macOS:

  1. Launch the terminal and locate the JavaVirtualMachines directory.

~ cd /Library/Java/JavaVirtualMachines

  1. List the directory’s contents with the ls command:


You’ll find that JDK installation in this directory. For instance, our test system contains JDK 18.0.2.

java virtual machines library

  1. Note the version number because it is used in the removal process. For instance, to uninstall JDK 18.0.2 from our test system, we’ll enter the following command:

~ sudo rm -rf jdk-18.0.2.jdk

Also Read: How to Check Java Version Installed on Linux


Users can take advantage of the capabilities of Java-based apps and development tools on their macOS computers by simply installing Java on their Mac. Whether you are a software developer creating Java applications or an end user running Java-based software, having a properly installed Java environment is essential for seamless functionality.

The process typically involves downloading the appropriate Java Development Kit (JDK) or Java Runtime Environment (JRE) from the official Oracle website or adopting alternatives like OpenJDK. To guarantee a seamless and error-free installation, users should adhere to the instructions included with the relevant distribution.

Looking for uncompromised performance and complete control over your hosting environment?

RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.


Q. How can I install Java on macOS?

To install Java on macOS, you can use Homebrew or download the JDK installation file from the official Java website. Once the file is downloaded, you can run the installation wizard to complete the installation process.

Q. Can I use Homebrew to install the latest version of Java on my Mac?

Yes, Homebrew is a popular package manager for macOS, and you can install the latest version of Java on your Mac by running the appropriate commands in the terminal.

Q. What is the purpose of the JAVA_HOME environmental variable?

The JAVA_HOME environment variable is used to specify the location of the JDK installation on your Mac. Java-based applications need to locate the JDK for compilation and execution.

Q. Is it possible for me to install different versions of Java on my Mac?

It is possible to run different versions of Java on your Mac. You can switch between different versions using the command-line tool or managing symbolic links.

Q. How do I switch between different versions of Java on my Mac?

To switch between different versions of Java on your Mac, you can use the “sudo ln -sfn” command to create symbolic links between the desired Java version and the default Java executable.

Q. Can I install OpenJDK on my Mac?

Yes, you can install OpenJDK, the open-source implementation of the Java Platform, on your Mac. It provides an alternative to the Oracle JDK and is compatible with Mac OS.

Q. What is the JDK version for macOS?

The JDK (Java Development Kit) version for macOS can vary based on the release from Oracle or OpenJDK. We recommend you install the latest version available for your system.

Q. How can I switch between different Java versions on macOS?

You can switch between different Java versions on macOS by updating the JAVA_HOME environment variable to point to the desired JDK installation directory. This allows you to switch between installed Java versions.

Q. Can I create a symbolic link for the JDK on macOS?

Yes, you can create a symbolic link for the JDK on macOS using the “ln” command in the terminal. This allows you to reference the JDK installation from a different location if needed.

Q. Can multiple versions of Java be installed on macOS?

 Yes, it is possible to have multiple versions of Java installed on macOS. You can manage different JDK installations and switch between them as needed for different applications or development projects.

Q. How do I install Java from a .dmg file on macOS?

To install Java from a .dmg file on macOS, simply open the .dmg package, locate the Java installer file, and follow the on-screen instructions to complete the installation process.

Try this guide with our instant dedicated server for as low as 40 Euros