Java JDKs on a Mac: Homebrew and SDKMAN copies measured, why java_home finds none, and how to remove them
Our test Mac had two JDKs installed through Homebrew, 312.7 and 382.7 MB, and <code>/usr/libexec/java_home -V</code> said it could not find a Java Runtime at all. Add three JDKs through SDKMAN (301 to 343 MB each) and the Mac holds five full JDKs that no single command lists. We measured every copy, tested what <code>java_home</code> finds and what it does when you ask for a version it does not have, and removed JDKs with each tool's own command.
What we measured
- Apple M4 Mac mini, macOS 27.0.1, 19 November 2026. The Homebrew JDKs were already installed:
openjdk27.0.1.0.3 andopenjdk@1717.0.21.0.2. - SDKMAN 5.24.0 in a scratch folder under
/tmpwith a scratchHOME(so nothing touched the real home folder), and Temurin 17.0.21+9, 21.0.13.1+2 and 25.0.5.0+8 from it. SDKMAN's installer needs Bash 4 or newer; macOS ships 3.2, so we added Homebrew's Bash for the run and removed it afterwards. - Sizes are
du -skin MB (1 MB = 1,024 KB). We have no Oracle.pkginstaller copy here (installing one needs an admin password), so/Library/Java/JavaVirtualMachinesstayed empty.
Five JDKs, three places
| JDK | Installed by | Folder | MB | Files |
|---|---|---|---|---|
| OpenJDK 27.0.1.0.3 | Homebrew openjdk | /opt/homebrew/Cellar/openjdk/ | 373.7 | 305 |
| OpenJDK 17.0.21.0.2 | Homebrew openjdk@17 | /opt/homebrew/Cellar/openjdk@17/ | 305.3 | 391 |
| Temurin 17.0.21+9 | SDKMAN | ~/.sdkman/candidates/java/17.0.21.0+9-tem | 309.4 | 456 |
| Temurin 21.0.13.1+2 | SDKMAN | ~/.sdkman/candidates/java/21.0.13.1+2-tem | 334.9 | 456 |
| Temurin 25.0.5.0+8 | SDKMAN | ~/.sdkman/candidates/java/25.0.5.0+8-tem | 294.2 | 400 |
Homebrew's own listing says 391.3 MB and 319.4 MB for the same two (it counts decimal MB); <code>du</code> gives the 373.7 and 305.3 above. The five together are 1,617.5 MB.
Where the space goes in one JDK: <code>lib/modules</code> is the runtime itself (123.0 MB in Temurin 17, 134.4 MB in 21, 137.9 MB in 25, 139.1 MB in Homebrew's 27). <code>jmods</code> is 70.4 MB in Homebrew's 17 and 81.1 MB in its 27, and it is only needed to build custom runtimes with <code>jlink</code>. Temurin 25 ships without a <code>jmods</code> folder, which is part of why it is the smallest of the three even though it is the newest.
Why java_home says there is no Java
This is the first thing to know on a Mac with Homebrew JDKs. Homebrew's <code>openjdk</code> formula is keg-only: it is not linked into the places macOS looks, and its caveat says to run <code>sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk</code>. Until then:
/usr/libexec/java_home -Vprinted Unable to locate a Java Runtime, exit code 1./usr/bin/java -versiongave the same message.JAVA_HOMEwas empty.- Yet both JDKs run fine when called by path.
SDKMAN copies are invisible to <code>java_home</code> for a different reason: SDKMAN keeps its own <code>current</code> link and sets <code>JAVA_HOME</code> per shell. The Temurin folders have <code>bin</code> and <code>lib</code> at the top level, not the <code>Contents/Home</code> layout macOS expects in a <code>.jdk</code> bundle, so they cannot be linked in either.
We tested the no-admin version of the Homebrew fix: symlinks to the two <code>openjdk.jdk</code> folders in <code>~/Library/Java/JavaVirtualMachines</code>, which <code>java_home</code> also reads. We removed them again afterwards. Then <code>java_home</code> found both, and we asked for versions:
| Command | Result |
|---|---|
java_home -V | lists 27.0.1.0.3 and 17.0.21.0.2 |
java_home -v 17 | the Homebrew 17 |
java_home -v 21 | Homebrew 27, exit code 0 (no 21 installed) |
java_home -v 28 | Homebrew 27, exit code 0 |
java_home -v 1.8 | Homebrew 27, exit code 0 |
java_home -v 21 --failfast | error, exit code 1 |
So <code>export JAVA_HOME=$(/usr/libexec/java_home -v 21)</code> on a Mac without a 21 quietly gives you 27 and a build that now fails in odd ways. Add <code>--failfast</code> in scripts if you want it to stop instead.
Duplicates across installers
- Two copies of the 17 line: Homebrew's 17.0.21.0.2 (305.3 MB) and Temurin 17.0.21+9 (309.4 MB). Their
lib/modulesfiles are both about 123 MB, but they are separate builds, so no clone or hard link shares the space. Keeping both costs 614.7 MB for one Java. - Homebrew is behind:
brew outdatedshowedopenjdk@1717.0.21.0.2 → 17.0.21.0.3. An upgrade installs the new folder and, untilbrew cleanupruns, can leave the old one. gradledepends on Homebrew'sopenjdk.brew uninstall openjdkrefused with required by gradle, which is currently installed. That is Homebrew protecting you; the folder is not a free duplicate if a formula uses it.- Not found on this Mac, worth a look on yours:
~/.gradle/jdks,~/.jdks(IntelliJ downloads),~/.m2/jdks, and ajbrfolder inside JetBrains or Android Studio apps.
Removing JDKs the supported way
| Where | Command | What we saw |
|---|---|---|
| SDKMAN | sdk uninstall java 21.0.13.1+2-tem | 966,960 → 623,976 KB: exactly the folder's 342,984 KB |
| SDKMAN, the default one | sdk uninstall java 17.0.21.0+9-tem | refused: is the default version. Run sdk default java 25.0.5.0+8-tem first, then it removed 316,864 KB |
| SDKMAN downloads | sdk flush | 10 archive(s) flushed, freeing 546M |
| Homebrew | brew uninstall openjdk@17 | refuses if a formula needs it; brew cleanup removes old versions and downloads |
Oracle or other .pkg | sudo rm -rf /Library/Java/JavaVirtualMachines/<name>.jdk | not tested here (no .pkg JDK installed) |
The <code>sdk flush</code> line is the surprise: SDKMAN keeps every downloaded zip in <code>tmp</code>. Our three installs left 558,920 KB there, more than a whole JDK. After the flush the SDKMAN folder went from 1,525,880 KB to 966,960 KB with all three JDKs still installed. Once the 21 and 17 were removed too, only the 25 (307,112 KB with SDKMAN itself) was left.
What to do on your Mac
/usr/libexec/java_home -Vshows only JDKs macOS can see. Then also runbrew list --versions | grep -i -E "jdk|java"andls ~/.sdkman/candidates/java.- Decide which major versions you build against (Maven, Gradle and CI files say) and keep one copy of each line, from one installer.
- Remove the rest with the tool that installed it, not by deleting folders.
- Run
sdk flushif you use SDKMAN. - In scripts, call
java_home -v N --failfastso a missing JDK stops the build rather than substituting the newest.
Zofle shows JDK folders from Homebrew, SDKMAN and <code>/Library/Java</code> in one list by size, next to the developer caches covered in our <a href="https://zofle.com/articles/node-version-managers-mac-nvm-fnm-volta-leftover-versions-measured">Node version managers article</a> and our <a href="https://zofle.com/articles/homebrew-mac-storage-cellar-caskroom-cache-cleanup">Homebrew storage article</a>.
Zofle lists JDKs, version managers and developer caches by size on disk and moves your picks to the Trash with Undo.
Download Zofle for MacSources and method
- Run on 19 November 2026 on one Apple M4 Mac mini, macOS 27.0.1. SDKMAN 5.24.0 (sdkman.io), Temurin builds from SDKMAN's list (
sdk list java); Homebrew formulasopenjdkandopenjdk@17as already installed. Scratch folders under/tmpwere deleted afterwards; the two test symlinks in~/Library/Javawere removed. - Sizes are
du -sk; one machine, one run. The Homebrew keg-only caveat is quoted frombrew info openjdk. The-vfallback behaviour is what we observed with this Mac's two JDKs on macOS 27; we did not read Apple documentation for it and it may differ on other versions.
Zofle Pro news
People signing up now will get Zofle Pro, with more features, for free when we launch it.