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

URL: https://www.kemptdesk.com/guides/developer-caches-node-modules-npm-cargo-gradle
Platform: Mac and PC
Applies to: macOS 13 Ventura and later, Windows 10 and 11; npm, pnpm, Yarn 1, Cargo, Gradle and pip as documented on the review date
Reviewed: 2026-11-23
Publisher: KemptDesk (https://www.kemptdesk.com), a disk clean-up app for Mac and PC

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.

## 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](https://www.kemptdesk.com/guides/mac-storage-full). On a PC they sit in your user profile on the C: drive, next to the items in [what fills a Windows C: drive](https://www.kemptdesk.com/guides/c-drive-full).

- `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](https://www.kemptdesk.com/guides/xcode-derived-data-simulators). Docker images and WSL systems live in one big disk file each; see [how to shrink a WSL or Docker disk](https://www.kemptdesk.com/guides/shrink-wsl-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>/node_modules` | 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/_cacache` | npm's download cache (`%LocalAppData%\npm-cache` 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` |
| `~/.cargo/registry` | 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/bin` | `cargo`, `rustc` and tools you installed with `cargo install` | No | Cargo and your installed tools stop working | Uninstall tools with `cargo uninstall` |
| `<project>/target` | Cargo build output for one project | Yes | The next build compiles everything again | `cargo clean` |
| `~/.gradle/caches` | Downloaded dependencies and Gradle build caches | Yes | The next build downloads dependencies again and runs slower | Stop the daemons, then delete it |
| `~/.gradle/gradle.properties` | Your Gradle settings, sometimes with credentials | No | Builds lose settings, keys or repository passwords | Keep it |
| `~/Library/Caches/pip` | pip's wheel and download cache (`%LocalAppData%\pip\Cache` on Windows) | Yes | pip downloads packages again | `pip cache purge` |

> **Careful:** Delete `~/.gradle/caches`, not the whole `~/.gradle` folder. The parent folder also holds `gradle.properties` and init scripts that a cache command does not recreate.

## 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

- [npm cache (npm Docs)](https://docs.npmjs.com/cli/v11/commands/npm-cache)
- [npm ci (npm Docs)](https://docs.npmjs.com/cli/v11/commands/npm-ci)
- [npm config: cache (npm Docs)](https://docs.npmjs.com/cli/v11/using-npm/config#cache)
- [pnpm store (pnpm Docs)](https://pnpm.io/cli/store)
- [yarn cache (Yarn 1 Docs)](https://classic.yarnpkg.com/en/docs/cli/cache)
- [Cargo Home (The Cargo Book)](https://doc.rust-lang.org/cargo/guide/cargo-home.html)
- [cargo clean (The Cargo Book)](https://doc.rust-lang.org/cargo/commands/cargo-clean.html)
- [Announcing Rust 1.88.0: Cargo automatic cache cleaning (Rust Blog)](https://blog.rust-lang.org/2025/06/26/Rust-1.88.0/)
- [Gradle directories and caches (Gradle User Manual)](https://docs.gradle.org/current/userguide/directory_layout.html)
- [Build environment and gradle.properties (Gradle User Manual)](https://docs.gradle.org/current/userguide/build_environment.html)
- [Caching (pip documentation)](https://pip.pypa.io/en/stable/topics/caching/)
