Skip to content

Every JDK you installed is still there, and they are 300 MB each

Java installs do not replace each other and several vendors ship their own. How to see what is on the machine and remove the rest.

4 min read

Installing a JDK never removes the previous one, and on Windows they come from several vendors that each install to their own folder. A machine that has done Android work, some server work and a course tutorial has three or four.

What is installed

Get-ChildItem 'C:\Program Files\Java','C:\Program Files\Eclipse Adoptium','C:\Program Files\Microsoft\jdk*','C:\Program Files\Amazon Corretto' -EA SilentlyContinue |
  ForEach-Object {
    $s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue | Measure-Object Length -Sum).Sum
    [PSCustomObject]@{ MB = [math]::Round($s/1MB); Path = $_.FullName }
  } | Sort-Object MB -Descending
java -version 2>&1
$env:JAVA_HOME

JAVA_HOME tells you which one your tools actually use. Everything else on that list is installed and idle unless a specific project points at it.

Removing the rest

Each JDK appears in Settings, Apps as its own entry and uninstalls cleanly from there. Deleting the folder instead leaves the entry and the registry keys behind, and on Windows that means Settings shows software that is not there.

The build caches beside them

Get-ChildItem "$env:USERPROFILE\.gradle","$env:USERPROFILE\.m2" -EA SilentlyContinue |
  ForEach-Object {
    $s = (Get-ChildItem $_.FullName -Recurse -Force -File -EA SilentlyContinue | Measure-Object Length -Sum).Sum
    '{0,8:N0} MB  {1}' -f ($s/1MB), $_.FullName
  }
FolderWhat it isSafe to clear
.gradle\cachesDownloaded dependenciesYes, refetched
.gradle\wrapper\distsA full Gradle per version any project pinnedYes, redownloaded
.m2\repositoryEvery Maven dependency ever resolvedYes, refetched
Project build and targetCompiled outputYes, rebuilt

The wrapper distributions

Each entry under wrapper\dists is a complete Gradle, 100 to 200 MB unpacked, downloaded because some project pinned that version. Anything no current project pins is dead weight, and the same is true of the Maven repository's older artefact versions.

On an Android machine these sit alongside much larger neighbours, covered in Android Studio on Windows.

Common questions

How do I see which JDKs are installed on Windows?

Look in Program Files for Java, Eclipse Adoptium, Microsoft and Amazon Corretto folders, and check JAVA_HOME to see which one your tools actually use.

Is it safe to delete old JDK folders?

Uninstall them through Settings, Apps instead. Deleting the folder leaves the entry and registry keys behind, so Settings lists software that is no longer there.

Why does .gradle have several Gradle versions?

Because each project pins its own version through the wrapper, and every version any project has asked for is downloaded and kept. None are removed when a project upgrades.

Can I delete the .m2 repository?

Yes. Everything in it came from a remote repository and is downloaded again on the next build. The only cost is a slow first build.

Read next