Java, a ubiquitous programming language and platform, is fundamental to a vast array of applications, from desktop software and web servers to mobile apps and scientific tools. For Mac users, having a correctly installed Java Development Kit (JDK) or Java Runtime Environment (JRE) is often a prerequisite for running specific software, developing new applications, or participating in various tech-related projects. This guide will walk you through the process of installing Java on your macOS system, ensuring you have the necessary components for your development or operational needs.
Understanding Java on macOS: JDK vs. JRE
Before diving into the installation process, it’s crucial to understand the distinction between the Java Development Kit (JDK) and the Java Runtime Environment (JRE). These are the two primary distributions of Java you’ll encounter.
The Java Runtime Environment (JRE)
The JRE is the component that allows you to run Java applications. It includes the Java Virtual Machine (JVM), which executes Java bytecode, and a set of core Java libraries. If your primary need is simply to run existing Java programs, the JRE is sufficient. Many applications that rely on Java will bundle their own JRE or prompt you to install one if it’s not detected.
The Java Development Kit (JDK)
The JDK is a superset of the JRE. It contains everything in the JRE, plus essential tools for developing Java applications. These tools include compilers (like javac), debuggers (like jdb), and archivers (like jar). If you plan to write, compile, and debug your own Java code, or if you’re working with development frameworks that require compilation, you will need to install the JDK. For most developers, installing the JDK is the standard practice, as it covers all runtime needs and provides development capabilities.
Choosing the Right Java Version
The Java ecosystem evolves rapidly, with new versions released regularly. Oracle’s Java SE (Standard Edition) is the most common platform. As of recent updates, Java 8 (LTS – Long-Term Support) and Java 11 (LTS), Java 17 (LTS), and the latest feature releases are widely used.
Long-Term Support (LTS) Versions
LTS versions are recommended for most users and production environments. They receive updates and support for an extended period, providing stability and predictability. Key LTS versions include:
- Java 8: Still widely used, especially in legacy enterprise systems.
- Java 11: A significant update with many performance improvements and new features.
- Java 17: The current LTS release, offering substantial enhancements and a robust foundation for modern development.
Latest Feature Releases
Newer feature releases (e.g., Java 18, 19, 20, 21) introduce the latest language features and performance optimizations. They have a shorter support lifecycle, making them ideal for developers who want to experiment with cutting-edge Java technologies or for projects that can readily adopt new releases.
When selecting a version, consider the requirements of the software you intend to run or the development frameworks you plan to use. Many modern tools are optimized for or specifically require newer Java versions.
Installing Java on Mac: Step-by-Step
The most common and recommended method for installing Java on macOS is by downloading the official JDK installer from Oracle or a reputable OpenJDK distributor.
Method 1: Installing Oracle JDK
Oracle provides official JDK builds that are widely compatible.
Step 1: Download the Oracle JDK Installer
- Navigate to the Oracle Java SE Downloads page: Open your web browser and go to the official Oracle Java SE Downloads website. You can typically find this by searching “Oracle Java SE Downloads” or directly navigating to
oracle.com/java/technologies/javase-downloads.html. - Select the Desired Java Version: On the downloads page, you will see different versions of Java SE available. Choose the version you need (e.g., JDK 17, JDK 11, or the latest).
- Choose macOS Installer: Under the chosen version, locate the “macOS” section. You will usually find a
.dmgfile option, which is the standard installer for macOS. Select the installer for your Mac’s architecture (usually “x64” for Intel Macs or “ARM64” for Apple Silicon Macs like M1, M2, etc.). If you are unsure, download thex64version, as it is backward compatible for most Intel Macs.
Step 2: Run the Installer
- Open the Downloaded
.dmgFile: Once the download is complete, locate the.dmgfile in your Downloads folder and double-click it to mount the disk image. - Launch the Installer Package: A window will appear showing the installer package (usually with a
.pkgextension). Double-click this package to start the installation wizard. - Follow the On-Screen Instructions: The installer will guide you through the process. You’ll typically need to agree to the license terms and select the installation destination. Most users can proceed with the default installation settings. You may be prompted for your administrator password to authorize the installation.
- Complete Installation: After the installation is finished, you can close the installer. The
.dmgfile can be ejected and deleted.
Step 3: Verify the Installation
To confirm that Java has been installed correctly and is accessible, you can use the Terminal application.
- Open Terminal: You can find Terminal in
Applications > Utilities > Terminal, or by searching for “Terminal” using Spotlight (Command + Space). - Check Java Version: Type the following command and press Enter:
bash
java -version
If the installation was successful, this command will display the version of the Java Runtime Environment that is currently active. - Check Java Compiler Version (if JDK installed): To verify the JDK installation and its compiler, type:
bash
javac -version
This command should output the version of the Java compiler (javac) corresponding to the JDK you installed.
Method 2: Installing OpenJDK
OpenJDK is an open-source implementation of the Java Platform, Standard Edition. Many developers prefer OpenJDK for its open nature and the availability of builds from various reputable sources. Adoptium (formerly AdoptOpenJDK) is a popular provider.

Step 1: Download OpenJDK from Adoptium
- Visit the Adoptium Website: Go to the Adoptium website (
adoptium.net). - Select Latest LTS or Latest Release: You will typically see options to download the latest LTS release (e.g., Temurin 17) or the latest feature release. Choose the version that best suits your needs.
- Download macOS Installer: Select “macOS” as your operating system and choose the appropriate architecture (x64 or AArch64/ARM64). Download the
.pkginstaller file.
Step 2: Run the Installer
- Open the Downloaded
.pkgFile: Locate the downloaded.pkgfile and double-click it. - Follow Installation Prompts: The installation process is similar to the Oracle JDK. Follow the on-screen instructions, accept the license agreement, and provide your administrator password if prompted.
Step 3: Verify the Installation
The verification process is the same as with the Oracle JDK:
- Open Terminal.
- Check Java Version:
bash
java -version
- Check Java Compiler Version:
bash
javac -version
Managing Multiple Java Versions (Advanced)
For developers working on projects that require different Java versions, managing multiple installations is essential. macOS’s default behavior often points to the most recently installed JDK. However, you can explicitly control which Java version is active.
Using JAVA_HOME Environment Variable
The JAVA_HOME environment variable is a standard way for Java applications and build tools to locate the Java installation. Setting this variable correctly ensures that your system and tools use the desired JDK.
Setting JAVA_HOME in .zshrc or .bash_profile
macOS modern versions use Zsh as the default shell. If you are using an older version of macOS, you might be using Bash.
-
Identify Your Java Installation Path:
- For Oracle JDKs, they are typically installed in
/Library/Java/JavaVirtualMachines/. - For Adoptium Temurin, they are often in
/Library/Java/JavaVirtualMachines/temurin-<version>-<arch>.jdk/Contents/Home.
You can list installed JDKs with:
/usr/libexec/java_home -VThis command will list all detected JDKs and their paths. Copy the path to the JDK you want to set as default (e.g.,
/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home). - For Oracle JDKs, they are typically installed in
-
Edit Your Shell Profile:
- For Zsh: Open or create the
.zshrcfile in your home directory:
bash
nano ~/.zshrc
- For Bash: Open or create the
.bash_profilefile in your home directory:
bash
nano ~/.bash_profile
- For Zsh: Open or create the
-
Add
JAVA_HOMEExport: Add the following lines to the file, replacing the path with your chosen JDK’s home directory.export JAVA_HOME=$(/usr/libexec/java_home -v <version_number>) export PATH=$JAVA_HOME/bin:$PATHFor example, to set Java 17 as default:
export JAVA_HOME=$(/usr/libexec/java_home -v 17) export PATH=$JAVA_HOME/bin:$PATHAlternatively, you can manually specify the path:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home export PATH=$JAVA_HOME/bin:$PATH -
Save and Exit: Press
Ctrl + X, thenYto confirm saving, andEnterto exit nano. -
Apply Changes: Either close and reopen your Terminal window, or run:
source ~/.zshrc # or source ~/.bash_profile -
Verify
JAVA_HOME:
bash
echo $JAVA_HOME
java -version
Theecho $JAVA_HOMEcommand should display the path you set, andjava -versionshould show the corresponding Java version.
Using jenv (Java Version Manager)
For more sophisticated management of multiple Java versions, consider using jenv (Java Environment Manager). jenv allows you to easily switch between different JDKs installed on your system.
-
Install
jenv: The easiest way to installjenvis using Homebrew:brew install jenv -
Configure Your Shell: Add
jenvto your shell’s initialization file (.zshrcor.bash_profile):echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc echo 'eval "$(jenv init - zsh)"' >> ~/.zshrcRemember to
sourceyour.zshrcfile or restart your Terminal. -
Add JDKs to
jenv: After installing your desired JDKs (e.g., using the Oracle or Adoptium installers), telljenvabout them:jenv add /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home jenv add /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/HomeYou can find the paths by running
/usr/libexec/java_home -V. -
Set Global or Local Java Version:
- Global: Set a default Java version for your entire system:
bash
jenv global 17
- Local: Set a Java version for a specific project directory:
bash
cd /path/to/your/project
jenv local 11
- Global: Set a default Java version for your entire system:
-
Verify:
bash
java -version
jenvwill automatically manage theJAVA_HOMEandPATHvariables based on your global or local settings.

Common Issues and Troubleshooting
- “Command not found: java”: This usually means Java is not installed, or its path has not been correctly set in your
PATHenvironment variable. Revisit the installation steps and ensure you’ve updated your shell profile. - Incorrect Java Version: If
java -versionshows an older version than expected, yourJAVA_HOMEvariable might be pointing to the wrong installation, or your shell profile was not sourced correctly. - Permissions Errors: During installation, ensure you have administrator privileges. If you encounter issues with running Java applications, check file permissions for the Java installation directory.
- Security Prompts: macOS may sometimes prompt you about running applications downloaded from the internet. Ensure you trust the source of your Java download.
By following these steps, you can successfully install and manage Java on your Mac, whether for running applications or for embarking on your journey into Java development.
