KemptDesk

Is it safe to delete node_modules and the npm, Cargo and Gradle caches?

For Mac and PCmacOS 13 Ventura and later, Windows 10 and 11; npm, pnpm, Yarn 1, Cargo, Gradle and pip as documented on the review dateReviewed 23 November 20267 min read

Quick answer

Yes. node_modules folders, the npm cache, Cargo target folders and ~/.gradle/caches hold downloads and build output that the tools fetch or rebuild. Use the tools' own commands, such as npm cache clean --force and cargo clean. Keep config files like ~/.gradle/gradle.properties, and stop running builds first.

On this page
  1. Where the caches are
  2. Which developer folders are safe to delete
  3. How to clean the caches by hand
  4. How KemptDesk handles this
  5. Questions
  6. Sources

Where the caches are

Each tool keeps one shared download cache in your home folder, plus build output inside every project.

On a Mac these folders are a common part of what fills a Mac storage. On a PC they sit in your user profile on the C: drive, next to the items in what fills a Windows C: drive.

  • node_modules: inside each JavaScript project folder.
  • npm cache: ~/.npm on a Mac, %LocalAppData%\npm-cache on Windows. Run npm config get cache to see yours.
  • pnpm store: run pnpm store path to see it.
  • Yarn 1 cache: run yarn cache dir to see it.
  • Cargo: ~/.cargo/registry and ~/.cargo/git on a Mac, %USERPROFILE%\.cargo on Windows, unless you set CARGO_HOME. Build output is in each project's target folder.
  • Gradle: ~/.gradle/caches on a Mac, %USERPROFILE%\.gradle\caches on Windows, unless you set GRADLE_USER_HOME.
  • pip: run pip cache dir to see it.

Xcode keeps its own build data; see Xcode DerivedData and simulators. Docker images and WSL systems live in one big disk file each; see how to shrink a WSL or Docker disk.

Which developer folders are safe to delete

PathWhat it isSafe to deleteWhat happens if you delete itHow to clean it
<project>/node_modulesPackages installed for one projectYesThe project does not run until you install again; without a lockfile, newer versions can come innpm ci or delete it, then npm install
~/.npm/_cacachenpm's download cache (%LocalAppData%\npm-cache on Windows)Yesnpm downloads packages again when it needs themnpm cache clean --force
pnpm store (run pnpm store path)pnpm's shared content storeYespnpm downloads removed packages again on the next installpnpm store prune
Yarn 1 cache (run yarn cache dir)Yarn 1 download cacheYesYarn downloads packages againyarn cache clean
~/.cargo/registryDownloaded crates and their unpacked sourcesYesCargo downloads or unpacks crates again on the next buildLet Cargo clean it, or delete cache and src inside it
~/.cargo/bincargo, rustc and tools you installed with cargo installNoCargo and your installed tools stop workingUninstall tools with cargo uninstall
<project>/targetCargo build output for one projectYesThe next build compiles everything againcargo clean
~/.gradle/cachesDownloaded dependencies and Gradle build cachesYesThe next build downloads dependencies again and runs slowerStop the daemons, then delete it
~/.gradle/gradle.propertiesYour Gradle settings, sometimes with credentialsNoBuilds lose settings, keys or repository passwordsKeep it
~/Library/Caches/pippip's wheel and download cache (%LocalAppData%\pip\Cache on Windows)Yespip downloads packages againpip cache purge

How to clean the caches by hand

Close your editor and stop dev servers, watchers and builds first. A tool that writes to a cache while you delete it can leave a broken install.

node_modules

  1. Open a terminal in the project folder.
  2. Check that package-lock.json (or pnpm-lock.yaml or yarn.lock) exists, so the reinstall gets the same versions.
  3. Delete the folder and install again.

On a Mac, these commands delete the project's node_modules and install it again:

zsh
rm -rf node_modules
npm install

On Windows, in PowerShell in the project folder:

powershell
Remove-Item -Recurse -Force node_modules
npm install

npm ci does the same in one step: if a node_modules folder exists, npm removes it before it installs from the lockfile.

npm, pnpm and Yarn caches

The first command checks the npm cache and removes data it does not need. The second deletes everything in the npm cache folder.

bash
npm cache verify
npm cache clean --force

npm asks for --force because its cache repairs itself, so you only need to clear it to get disk space back. For pnpm, the first command removes packages that no project uses. For Yarn 1, the second command empties the cache.

bash
pnpm store prune
yarn cache clean

Cargo target folders and registry

  1. In each Rust project you no longer build often, run cargo clean. It deletes the project's target folder.
  2. For the shared cache, you can usually do nothing. Since Rust 1.88, Cargo deletes cache files that it downloaded and has not used for 3 months.
  3. To free the space now, delete cache and src inside the registry folder. The Cargo Book says Cargo restores any removed part of its cache when a crate needs it.
bash
cargo clean

On a Mac, this command deletes the downloaded crate archives and unpacked sources:

zsh
rm -rf ~/.cargo/registry/cache ~/.cargo/registry/src

On Windows, in PowerShell:

powershell
Remove-Item -Recurse -Force "$env:USERPROFILE\.cargo\registry\cache", "$env:USERPROFILE\.cargo\registry\src"

Gradle caches

Gradle cleans its own caches about once a day, after the daemon stops. It deletes downloaded files that no build used for 30 days. To free the space now, stop the Gradle daemons first, then delete only the caches folder. In a project with the Gradle wrapper, these commands do that on a Mac:

zsh
./gradlew --stop
rm -rf ~/.gradle/caches

On Windows, in PowerShell in the project folder:

powershell
.\gradlew --stop
Remove-Item -Recurse -Force "$env:USERPROFILE\.gradle\caches"

pip cache

This command deletes all files in pip's cache:

bash
pip cache purge

How KemptDesk handles this

On the System Junk page, the Developer caches category covers ~/.npm/_cacache, ~/.cargo/registry/cache and ~/.gradle/caches on a Mac. On a PC it covers the npm, Yarn, pnpm, pip and Cargo download caches, but not Gradle. The category is off by default; tick it to include it. KemptDesk deletes these caches directly.

Hidden space measures dot-folders and colours them. Only the cache folders are Safe to clean (green): .npm/_cacache, .gradle/caches, .gradle/wrapper, .m2/repository, .nuget/packages and .cargo/registry. KemptDesk does not select them for you: Smart Care's Clean recommended leaves developer caches out, so a build never has to download everything again by surprise. The rest of .gradle and .m2 is Breaks an app (red), like .rustup, .nvm and the rest of .cargo. KemptDesk never removes gradle.properties, init.d, Maven settings.xml, settings-security.xml or toolchains.xml, Cargo credentials or Docker's config.json, and it never removes a folder that holds one of them.

KemptDesk never selects node_modules or target folders. Files inside node_modules are locked as app data unless you turn on expert mode. KemptDesk does not run npm, Cargo or Gradle commands.

Questions

Is it safe to delete node_modules?

Yes, if the project has a lockfile. Run npm install or npm ci afterwards to get the same packages back. Old projects you no longer open are the best place to start.

Is npm cache clean --force safe?

Yes. It only empties npm's download cache, not your projects. The next install downloads packages again, so it is slower and needs a network connection.

Can I delete the .gradle folder?

Delete ~/.gradle/caches, not the whole folder. The .gradle folder can also hold gradle.properties with signing keys or repository credentials, and init scripts.

Why is my Rust target folder so big?

Cargo keeps compiled output for every profile and dependency in target. Run cargo clean in projects you do not build often; the next build compiles everything again.

Does deleting caches make builds break?

No, as long as you have a network connection and the packages still exist in their registry. Without a network, or with a private registry you can no longer reach, keep the caches.

Sources

See what is safe to delete on your computer

KemptDesk scans your disk, explains every folder and selects only what apps can rebuild. The scan is free and cleans up to 500 MB. No account.

Then pay once from $59 or yearly from $9.99 for the first year until 31 December 2026, then $24.99. One license covers Macs and PCs. See plans