There are a few libraries and tools you’ll definitely need to install before you can build or run Java-based software on your Mac. The first is the Java Development Kit (JDK)—a set of tools needed to create applications that run on the Java platform. The second is a Java project management tool like Maven or an Integrated Development Environment (IDE) like IntelliJ. This post is designed to walk you through installing Java on your Mac.
What is Java?
If you are planning to develop Java software, then you probably already know the answer. Java is an object-oriented programming language that allows developers to create software that runs on Java Virtual Machines. Using a virtual machine makes Java applications OS-independent. Therefore, you only need to write the code once and you can run it on Windows, Linux, and macOS.
How to Install Java on Mac
There are several different versions of JAVA that you can install. It depends on which version you choose. The first is the original, closed-source version developed by Oracle. The second is the open-source version called OpenJDK. The main difference between the two is the license. OpenJDK is more flexible in how you can use it, while the original version, which is owned by Oracle, is easier to install.
How to install Oracle JDK
Oracle JDK uses a disk image installer, like many other macOS applications.
- Open a web browser and go to Oracle’s Java download site.
- Click the macOS tab.
- You’ll see a few download links. The two relevant links are the ARM64 DMG Installer and the x64 DMG Installer. If you have an Apple Silicon Mac, you’ll need the ARM64 DMG. If you have an Intel Mac, you’ll need the x64 DMG.
- Click the link to download the DMG appropriate for your Mac.
- Once the DMG file has finished downloading, double-click it to mount it.
- In the mounted disk image, double-click the JDK pkg file.
- Click Continue on the welcome screen.
- Click Settings.
- Enter your administrator password when prompted.
- Wait for the installer to complete, then click Close.
- To confirm successful installation, go to Applications > Utilities and open Terminal. Then, type
java -version
and press Enter. - You should see a response telling you the version of Java you just installed.
How to install OpenJDK
OpenJDK doesn’t have an installer like Oracle JDK, so you’ll need to install it through Terminal. The easiest way to do this is to use Homebrew. If you don’t have Homebrew installed, you’ll need to install it first. If you’re not sure, open a Terminal window, type ,brew -v
and press Enter.

If you see the Homebrewversion information returned as shown then it is installed.
If not installed, follow the steps below:
- Before you can install Homebrew, you need to install Command Line Tools.
- To check if it’s installed, type ‘xcode-select version’
xcode-select -v
in a Terminal window. If your system returns the version information‘xcode-select version‘, then it’s installed. If not, type ‘ xcode-select version’xcode-select --install
to install it. - After installing Command Line Tools, use this command to install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL //raw.githubusercontent.com/Homebrew/install/master/install)"
- PressEnter, read the message that appears, and then pressEnteragain.
- Enter your admin password, pressEnterand wait for the message indicating successful installation.
- Once Homebrew is installed, use this command to install OpenJDK:
brew install openjdk@
<version number> (replace <version number>with the version of OpenJDK you want to install, e.g. for version 21)brew install openjdk@21
- Press Enter and wait for the installation to complete.
How to install Java runtime on macOS
If you are not developing Java applications, just want to run Java applications, you do not need to install Java SDK. However, you need to install Java runtime environment because it is no longer installed on macOS.
How to install:
- Visit the Java website://www.oracle.com/java/technologies/javase/jdk19-archive-downloads.html
- ClickDownload Java.
- On the next page, clickDownload Java.
- Once theDMGfile has finished downloading, double-click it to open it.
- Double click the pkg file to start the installation.
- ClickSettings.
- When the installation is complete, clickClose.
Note:
- The Java runtime allows you to run Java applications that have been written and compiled by others.
- If you want to develop Java applications, you need to install Java Development Kit (JDK) as instructed in the section above.
Check settings:
Open Terminal and typejava -version
. If you see information about the installed Java version, it means the installation was successful.
Additional Resources:
How to Uninstall Java from macOS
Uninstall Java using Terminal:
- Open Terminal.
- Enter the following command to uninstall the Java Development Kit (JDK):
sudo rm -fr /Library/Java/JavaVirtualMachines/*.jdk
- Enter the following command to uninstall the Java runtime environment (JRE):
sudo rm -fr /Library/Internet Plug-Ins/JavaAppletPlugin.plugin
- Enter the administrator password when prompted.
Uninstall Java using the installer:
- Visit Oracle’s Java download site://www.oracle.com/java/technologies/javase/jdk19-archive-downloads.html
- Select themacOStab .
- Download the DMG file named “Java SE Development Kit 19“.
- Open the DMG file and run the installer.
- Select the “ Uninstall Java” option during the installation process.
Note:
- After uninstalling Java, you may need to restart your Mac.
- Manually deleting leftover Java folders may cause system errors.
You may be interested in:How to install GIT on macOS
Conclude
In the above article, I have given detailed instructions on how to install Java JDK, as well as how to install Java runtime environment for those who only want to run Java applications on macOS. In addition to installation, I also instructed you how to uninstall Java on macOS cleanly when not in use.