Skip to content

Four JDKs and three Gradles: how a Mac ends up with 2.3 GB of JVM

JDKs arrive from Homebrew, from installers and from casks, and each keeps its own copy. Measured: four JDKs at 1.51 GB and three Gradle versions.

5 min read

Nobody installs four JDKs on purpose. One comes from Homebrew as a dependency of a build tool, one from an installer an Android or Kotlin tutorial asked for, one from a cask, and Homebrew keeps the old version when it upgrades the new one.

What was installed

WhereWhatSize
/opt/homebrew/Cellar/openjdkVersions 23.0.2 and 25, side by side710 MB
/opt/homebrew/Cellar/openjdk@17JDK 17305 MB
/Library/Java/JavaVirtualMachines/zulu-17.jdkA second JDK 17, from Azul315 MB
/opt/homebrew/Caskroom/zulu@17The installer that put it there184 MB
/opt/homebrew/Cellar/gradleGradle 9.1.0519 MB
~/.gradle/wrapper/distsGradle 8.13 and 9.2.1289 MB

Two JDK 17s, an OpenJDK 23 that 25 replaced, and three Gradles: one global from Homebrew and two downloaded by project wrappers. Projects use their wrapper, so the Homebrew Gradle may not be run by anything.

Find yours

/usr/libexec/java_home -V
ls /opt/homebrew/Cellar | grep -iE 'jdk|java|gradle|maven'
ls /Library/Java/JavaVirtualMachines ~/Library/Java/JavaVirtualMachines 2>/dev/null
du -sh /opt/homebrew/Cellar/openjdk*/* 2>/dev/null

Removing the extras

  • Old Homebrew versions: brew cleanup openjdk removes every version except the newest.
  • A JDK nothing depends on: check with brew uses --installed openjdk@17 before brew uninstall openjdk@17.
  • A JDK in /Library/Java: installed by a package or cask. If it came from a cask, brew uninstall --cask zulu@17 removes both it and the installer copy.
  • Gradle: if every project uses ./gradlew, the Homebrew Gradle is optional. The wrapper downloads are covered in the Gradle folder.

Maven's repository is the other JVM cost, in the Maven repository, and Android Studio bundles yet another JDK, in Android Studio disk space.

Common questions

How do I list every JDK on a Mac?

Run /usr/libexec/java_home -V for the ones macOS knows about, then check /opt/homebrew/Cellar for Homebrew installs, which do not always register.

Why do I have two copies of the same Java version?

Because different installers each bring their own. On the Mac measured, JDK 17 came from both Homebrew and an Azul Zulu cask.

How do I remove old Java versions from Homebrew?

Run brew cleanup openjdk. Homebrew keeps the previous version after an upgrade until you do.

Is it safe to delete a JDK?

Yes, if nothing uses it. Check brew uses --installed and your projects' Java version setting first.

Read next