Brew Install Java - Easy Cask Method
Brew install Java on Mac. An easy Homebrew way to install the recommended Temurin JDK. The cask method without PATH or symlink configuration. How to fix common Homebrew Java issues.
Installing Java on macOS can be confusing. There's a maze of vendors, versions, and installation options. My recommendation for most developers: Install the newest Java 25 from Eclipse Temurin using the Homebrew cask method. This is the easy approach most developers prefer for Java, that works immediately without extra configuration. If you don't want to use Homebrew, my article Download Java for Mac describes other options.
If you're not sure whether Java is already on your Mac, see Check Java Version on Mac.
If you're not familiar with Homebrew, it's a package manager for macOS that developers use to install, update, and remove other software. Most developers use Homebrew to install command-line software and set up a development environment. If you're already using Homebrew, it's convenient to use it to install Java. If you don't have Homebrew installed, see our guide How to Install Homebrew on Mac.
Before you get started
You'll need a terminal application to install Java with Homebrew. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and makes coding easier when working with Java.
Casks vs Formulas
Homebrew offers two ways to install Java: casks and formulas. This guide covers the cask method.
Casks are preferable for Java development. The Homebrew cask installs Java with a symlink so the Java system launcher finds Java in the standard location on macOS for Java: /Library/Java/JavaVirtualMachines/. Java works immediately after installation. No additional configuration is required (except you may want to set the JAVA_HOME environment variable). Command line tools find Java automatically. This is what most developers want.
Formulas are better for Homebrew system use (as tool dependencies). Homebrew formulas install Java into Homebrew’s own directory structure and expose it via the Homebrew path (/opt/homebrew or /usr/local). This means Java behaves like other Homebrew‑managed tools, but it doesn’t automatically appear at the standard macOS Java location unless you add a symlink yourself. The openjdk formula is installed automatically when you install Java tools such as Maven with Homebrew. If you're sure you want the Homebrew formula for Java, see my other guide Brew Install Java - Formula Method.
Caution: What You Get With "brew install java"
If you try the simple and obvious brew install java, be aware you'll get the openjdk formula, not a cask. It's not recommended. The formula installation requires additional symlink configuration. If you ran brew install java and want the simpler cask approach, uninstall it first: with brew uninstall java.
Eclipse Temurin is Recommended
Java is open source, maintained by a wide community that includes major technology companies that operate as the Java Community Process (JCP) and produce the OpenJDK specification. The Java trademark is owned by Oracle, which sells enterprise licenses and distributes its own Java. Oracle Java is a closed‑source, commercially licensed build assembled from OpenJDK with a different support model.
The most widely recommended free OpenJDK distribution is Eclipse Temurin. Temurin comes from the Eclipse Foundation's Adoptium project, backed by enterprise members such as IBM, Azul, Google, and Microsoft. Temurin is:
- TCK-tested: Passes Oracle's Technology Compatibility Kit (over 100,000 tests)
- Free and open source: No licensing fees for commercial use
- Well-supported: Backed by Red Hat, IBM, Microsoft, Azul, and others
- Native builds available: Optimized binaries for both Apple Silicon and Intel Macs
Temurin is "official" Java—it is built from the same OpenJDK source code that Oracle and other vendors use. All third-party JDK vendors claim TCK compliance. The difference that matters is licensing, since Oracle Java is encumbered by restrictions and Temurin is not. Take a look at whichjdk.com for detailed (and opinionated) comparisons.
Before You Begin
If you do not have Homebrew yet, see our guide: Install Homebrew.
Check if Homebrew is Installed
Learn How to Open Terminal in Mac and run:
$ brew --version
You should see output like Homebrew 5.0.8. If Homebrew is not installed, you will see zsh: command not found: brew. See Zsh: command not found: brew if you think Homebrew is already installed. Otherwise, see our instructions to Install Homebrew.
Update Homebrew
Before installing Java, update Homebrew to get the latest package information:
$ brew update
==> Updating Homebrew...
This prevents "cask not found" errors from outdated metadata.
Which Version Should You Install
Java 25 is the current Long-Term Support (LTS) release, meaning it receives security updates until at least September 2033.
- Java 25 – Current LTS (recommended), supported until September 2033
- Java 21 – Previous LTS, supported until September 2031
- Java 17 – Extended LTS, supported until September 2029
- Java 11 – Extended LTS, for legacy projects
- Java 8 – Extended LTS, for legacy systems only
Use Java 25 unless your team or your university course specifically requires an older version. See Java Latest Version and Compare Java 21 to Java 25 for more information about versions.
Brew Install Java
Here is how to install Java 25 from the popular Eclipse Temurin distribution. This single command downloads and installs Java to the correct location:
$ brew install --cask temurin@25
The --cask flag tells Homebrew to install a prebuilt package as a Mac application. The @25 specifies Java 25, the current LTS version. If you enter brew install --cask temurin (without a version number), Homebrew will install the latest version. Homebrew recommends the temurin@25 naming instead of temurin25, though you may not see the @ form on older documentation.
Homebrew downloads the Temurin distribution, then asks for your password to run an installer. Enter the password you use to log in to your Mac; you won't see the password when you enter it.
The Homebrew cask method installs a JDK so that it appears under /Library/Java/JavaVirtualMachines/temurin-25.jdk/, the standard Java location on macOS, but that bundle ultimately resolves via symlinks into Homebrew’s own cask storage under the Caskroom (for example, /opt/homebrew/Caskroom or /usr/local/Caskroom, depending on whether you have an Apple Silicon or Intel Mac).
After installation, read on below to configure your JAVA_HOME environment variable.
Alternative Distributions
Eclipse Temurin works well for most developers. However, you might choose a different distribution for specific use cases. The installation process is identical for all distributions—just substitute the cask name.
- Eclipse Temurin – Cask
temurin@25, best for general development (recommended) - Amazon Corretto – Cask
corretto@25, best for AWS development environments - Azul Zulu – Cask
zulu@25, OpenJDK with commercial support - Microsoft OpenJDK – Cask
microsoft-openjdk, best for Azure development - Oracle JDK – Cask
oracle-jdk, if your company has an Oracle license
My article Download Java for Mac compares other vendor's distributions.
Install Other Java Versions
You can install multiple versions side by side. Each version installs to its own directory. The command brew search temurin will show all Temurin Java versions that are available. If you need the Java 21 version, use $ brew install --cask temurin@21. See Java Version Managers for help switching Java versions.
Set JAVA_HOME
Cask installations work immediately for basic use. Apple’s macOS exposes the java command at /usr/bin/java, which is a symlink to a small system Java launcher that uses any JDKs at the macos standard Java location /Library/Java/JavaVirtualMachines (and the Homebrew cask creates a symlink from the Homebrew Caskroom to the macos standard Java location). Since /usr/bin is already in the default PATH on macOS, you get a working java command without touching your shell configuration. You can immediately run java -version successfully.
However, the JAVA_HOME environment variable is not set because Homebrew does not modify your shell configuration files. You may need to set the JAVA_HOME environment variable if you use build tools like Gradle or Maven, or Java-based IDEs like Android Studio. For basic command-line Java usage, you may not need JAVA_HOME at all, but it's better to set it to avoid surprises later.
To set JAVA_HOME, use this shortcut to add the environment variable to your shell configuration .zprofile file (see .zshrc or .zprofile):
$ echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.zprofile
$ source ~/.zprofile
Read Set JAVA_HOME on Mac for complete configuration instructions. See the article Mac Shell Configuration for instructions about editing shell configuration files.
Java PATH
After installing Java as a Homebrew cask, you don't need to set the Mac $PATH.
On macOS, Java is handled differently from most other languages because macOS includes its own Java launcher at /usr/bin/java, which is a small program that locates and runs a JDK executable rather than being the JDK itself. When you install the Homebrew Java cask, it places a JDK bundle in the standard Homebrew directory and creates a symlink to the standard macOS Java location /Library/Java/JavaVirtualMachines/<something>.jdk/. The macOS Java launcher is preset to look in this standard directory, so when you type java in the terminal, the shell finds /usr/bin/java because /usr/bin is already on the default PATH, and the launcher then searches /Library/Java/JavaVirtualMachines and finds a symlink and runs the java binary in the Homebrew directory. Because the launcher is already installed, and the lookup logic lives in the launcher, and the launcher itself is already on PATH, you don’t need to add the JDK’s own directory to PATH just to make the java command work. Because Apple favors Java with a built-in launcher, and Homebrew creates a symlink, the java command works without setting $PATH.
Verify the Installation
Here is how to check if Java is installed correctly. See Check Java Version on Mac for a full set of checks.
Brew list
To confirm Homebrew installed the package:
$ brew list temurin@25
==> Pkg
OpenJDK25U-jdk_aarch64_mac_hotspot_25.0.1_8.pkg (Pkg)
Check the Java Version
Run:
$ java -version
You should see output like:
openjdk version "25.0.1" 2025-10-21
OpenJDK Runtime Environment Temurin-25.0.1+8 (build 25.0.1+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.1+8 (build 25.0.1+8-LTS, mixed mode)
The output shows the version number and confirms the Temurin distribution.
Additional Verification Commands
Check the Java compiler to confirmn you have the developer JDK:
$ javac -version
javac 25.0.1
Find the apparent Java binary location (from the $PATH environment variable):
$ which java
/usr/bin/java
List All Installed JDKs
macOS provides a utility to list every JDK it recognizes:
$ /usr/libexec/java_home -V
Output looks like:
Matching Java Virtual Machines (1):
25.0.1 (arm64) "Eclipse Adoptium" - "OpenJDK 25.0.1" /Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home
Cask-installed Java appears here immediately after installation.
Is JAVA_HOME set?
If you've Set JAVA_HOME on Mac in your shell configuration file and reset your terminal application, you can verify it:
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/temurin-25.jdk/Contents/Home
Update Java
Java receives quarterly security updates. Keep your installation current. Read Update Java on Mac for more about keeping Java current.
Check for Updates
See which casks have updates available:
$ brew outdated --cask
Upgrade Java
Update to the latest version:
$ brew upgrade --cask temurin@25
Clean Up Old Downloads
Reclaim disk space by removing old cached files:
$ brew cleanup
See Housekeeping for Homebrew for more on how to keep Homebrew and its packages up to date.
Uninstall Java
Here is how to remove Java cleanly.
Remove the Installation
$ brew uninstall --cask temurin@25
==> Uninstalling Cask temurin@25
==> Uninstalling packages with `sudo` (which may request your password)...
net.temurin.25.jdk
Password:
==> Purging files for version 25.0.1,8 of Cask temurin@25
You'll be prompted for your system password.
Verify Removal
Confirm the JDK is gone:
$ /usr/libexec/java_home -V
Check the installation directory:
$ ls /Library/Java/JavaVirtualMachines/
Final Cleanup
Remove any cached files:
$ brew cleanup
Read next: Uninstall Java on Mac for complete removal instructions including manual installations.
Troubleshooting
Here are solutions to common problems with cask installations.
Error: Cask 'temurin@25' is not available
Cause: Homebrew metadata is outdated.
Fix: Update Homebrew and search for the correct cask name:
$ brew update
$ brew search temurin
java: command not found after installation
This is rare with cask installations. The shell may not have refreshed its command cache.
Fix: Clear the shell cache and try again:
$ hash -r
$ java -version
Using hash -r in the current shell stops using stale command locations and picks up the new ones. If that does not work, open a new Terminal window.
Read Unable to Locate a Java Runtime for detailed troubleshooting steps.
Wrong Java Version Running
Cause: Multiple Java versions are installed and the wrong one is the default.
Fix: Check what is installed and set JAVA_HOME explicitly:
$ /usr/libexec/java_home -V
$ export JAVA_HOME=$(/usr/libexec/java_home -v 25)
$ java -version
This sets the JAVA_HOME environment variable temporarily. You'lll need to configure your .zprofile shell configuration file to make it permanent.
Note About Outdated Tutorials
Many older tutorials instruct you to run brew tap homebrew/cask-versions before installing versioned Java casks. This tap is deprecated. Modern Homebrew uses the @ syntax directly:
$ brew install --cask temurin@25
If you see warnings about homebrew-cask-versions being deprecated, you can safely remove it:
$ brew untap homebrew/cask-versions
What's Next
You now have Java installed and ready to use. If you need to switch between multiple Java versions for different projects, see Java Version Managers to learn about jEnv, SDKMAN, and other tools for switching Java versions.
My mac.install.guide is a trusted source of installation guides for professional developers. Take a look at the Mac Install Guide home page for tips and trends and see what to install next.