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
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:
~/.npmon a Mac,%LocalAppData%\npm-cacheon Windows. Runnpm config get cacheto see yours. - pnpm store: run
pnpm store pathto see it. - Yarn 1 cache: run
yarn cache dirto see it. - Cargo:
~/.cargo/registryand~/.cargo/giton a Mac,%USERPROFILE%\.cargoon Windows, unless you setCARGO_HOME. Build output is in each project'stargetfolder. - Gradle:
~/.gradle/cacheson a Mac,%USERPROFILE%\.gradle\cacheson Windows, unless you setGRADLE_USER_HOME. - pip: run
pip cache dirto 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
| Path | What it is | Safe to delete | What happens if you delete it | How to clean it |
|---|---|---|---|---|
<project>/ | Packages installed for one project | Yes | The project does not run until you install again; without a lockfile, newer versions can come in | npm ci or delete it, then npm install |
~/ | npm's download cache (%LocalAppData%\ on Windows) | Yes | npm downloads packages again when it needs them | npm cache clean --force |
pnpm store (run pnpm store path) | pnpm's shared content store | Yes | pnpm downloads removed packages again on the next install | pnpm store prune |
Yarn 1 cache (run yarn cache dir) | Yarn 1 download cache | Yes | Yarn downloads packages again | yarn cache clean |
~/ | Downloaded crates and their unpacked sources | Yes | Cargo downloads or unpacks crates again on the next build | Let Cargo clean it, or delete cache and src inside it |
~/ | cargo, rustc and tools you installed with cargo install | No | Cargo and your installed tools stop working | Uninstall tools with cargo uninstall |
<project>/ | Cargo build output for one project | Yes | The next build compiles everything again | cargo clean |
~/ | Downloaded dependencies and Gradle build caches | Yes | The next build downloads dependencies again and runs slower | Stop the daemons, then delete it |
~/ | Your Gradle settings, sometimes with credentials | No | Builds lose settings, keys or repository passwords | Keep it |
~/ | pip's wheel and download cache (%LocalAppData%\ on Windows) | Yes | pip downloads packages again | pip 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
- Open a terminal in the project folder.
- Check that
package-lock.json(orpnpm-lock.yamloryarn.lock) exists, so the reinstall gets the same versions. - Delete the folder and install again.
On a Mac, these commands delete the project's node_modules and install it again:
rm -rf node_modules
npm installOn Windows, in PowerShell in the project folder:
Remove-Item -Recurse -Force node_modules
npm installnpm 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.
npm cache verify
npm cache clean --forcenpm 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.
pnpm store prune
yarn cache cleanCargo target folders and registry
- In each Rust project you no longer build often, run
cargo clean. It deletes the project'stargetfolder. - 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.
- To free the space now, delete
cacheandsrcinside the registry folder. The Cargo Book says Cargo restores any removed part of its cache when a crate needs it.
cargo cleanOn a Mac, this command deletes the downloaded crate archives and unpacked sources:
rm -rf ~/.cargo/registry/cache ~/.cargo/registry/srcOn Windows, in 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:
./gradlew --stop
rm -rf ~/.gradle/cachesOn Windows, in PowerShell in the project folder:
.\gradlew --stop
Remove-Item -Recurse -Force "$env:USERPROFILE\.gradle\caches"pip cache
This command deletes all files in pip's cache:
pip cache purgeHow 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
- npm cache (npm Docs)
- npm ci (npm Docs)
- npm config: cache (npm Docs)
- pnpm store (pnpm Docs)
- yarn cache (Yarn 1 Docs)
- Cargo Home (The Cargo Book)
- cargo clean (The Cargo Book)
- Announcing Rust 1.88.0: Cargo automatic cache cleaning (Rust Blog)
- Gradle directories and caches (Gradle User Manual)
- Build environment and gradle.properties (Gradle User Manual)
- Caching (pip documentation)