WTMemory guide

How to clear the npm, Yarn and pnpm cache on Mac

Updated 13 October 2026

To clear the npm cache on a Mac, run npm cache clean --force; for pnpm run pnpm store prune, for Yarn 1 yarn cache clean, and for Yarn 2 or later yarn cache clean --all. These are download caches, so deleting them is safe: the only cost is that the next install downloads packages again.

WTMemory, a free macOS menu-bar app, can show the size of these caches side by side before you clear anything. More on that at the end; the commands below need nothing but Terminal.

How much space are my package caches using?

Measure first, so you know which cache is worth the trouble. These are the default macOS locations:

du -sh ~/.npm ~/Library/pnpm/store ~/Library/Caches/Yarn ~/.yarn/berry/cache \
  ~/.bun/install/cache ~/.cargo/registry ~/.cargo/git ~/.gradle/caches 2>/dev/null

If you changed a location through config or environment variables, ask the tool directly:

ToolDefault location on macOSAsk the toolClear it
npm~/.npm/_cacachenpm config get cachenpm cache clean --force
pnpm~/Library/pnpm/storepnpm store pathpnpm store prune
Yarn 1~/Library/Caches/Yarnyarn cache diryarn cache clean
Yarn 2+~/.yarn/berry/cacheyarn config get cacheFolderyarn cache clean --all
Bun~/.bun/install/cachebun pm cachebun pm cache rm
Cargo~/.cargo/registry, ~/.cargo/gitecho $CARGO_HOMEDelete registry/cache and registry/src
Gradle~/.gradle/cachesecho $GRADLE_USER_HOMEStop daemons, delete caches

How do I clear the npm cache on Mac?

npm cache clean --force

npm keeps downloaded tarballs in a content-addressed store under ~/.npm/_cacache. Since npm 5 the cache checks its own integrity, which is why npm refuses to clean without --force. If you only suspect corruption, npm cache verify garbage-collects unneeded data and checks the rest without throwing everything away.

Two neighbours in ~/.npm are also safe to remove: _npx, which holds packages fetched by npx, and _logs, which holds debug logs. Clearing the cache does not touch any project or your global installs.

How do I clear the pnpm store?

pnpm store prune

pnpm keeps one copy of every package version in a global store and hard-links files from it into each project's node_modules. prune removes packages that no project references any more. Do not run it while an install is in progress. Run pnpm store path to see the exact folder; the store directory name includes a version (such as v10) that changes between major pnpm releases, so an old version folder can be left behind after an upgrade.

Because of hard links, du on the store and on your projects counts the same bytes twice, and deleting the whole store frees little while projects still link to those files. Prune first, then remove node_modules in projects you no longer work on.

How do I clear the Yarn cache?

Check your version with yarn --version. Yarn 1 (classic) uses ~/Library/Caches/Yarn:

yarn cache clean

Yarn 2 and later (Berry) keeps a global cache in ~/.yarn/berry/cache by default, and some repositories use a per-project .yarn/cache instead. To clear both the global and the current project's cache:

yarn cache clean --all

If a repository commits .yarn/cache to git for zero-installs, do not delete it by hand: it is part of the repo.

How do I clear the Bun cache?

bun pm cache rm

Bun stores downloaded packages in ~/.bun/install/cache unless BUN_INSTALL_CACHE_DIR says otherwise. bun pm cache prints the path. Leave ~/.bun/bin alone, because that is where the bun binary itself lives.

How do I clear the Cargo cache?

Cargo keeps downloaded crates as compressed archives in ~/.cargo/registry/cache and unpacked sources in ~/.cargo/registry/src. Both are safe to delete, and Cargo fetches them again on the next build:

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

~/.cargo/git/checkouts holds git dependencies and can go too. Do not delete ~/.cargo/bin (tools installed with cargo install) or ~/.cargo/credentials.toml. The bigger Rust win is usually each project's target folder, which you clear with cargo clean inside the project.

How do I clear the Gradle cache?

Stop the Gradle daemons first, because they hold files in the cache open:

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

The next build re-downloads dependencies and rebuilds transforms, which can take a while on Android projects. ~/.gradle/wrapper/dists holds a full Gradle distribution for every wrapper version you have used; delete old versions you no longer build with. Keep ~/.gradle/gradle.properties, which often contains signing and repository credentials.

How do I find node_modules folders taking up space?

On a Mac with many projects, node_modules folders usually outweigh the global caches. List them with sizes, replacing ~/code with wherever you keep projects:

find ~/code -name node_modules -type d -prune -exec du -sh {} + | sort -h

-prune stops find from descending into each node_modules, so nested dependency folders are not listed separately and the scan stays fast. Delete the ones in projects you are not actively working on:

rm -rf ~/code/old-project/node_modules

The lockfile in the project restores the exact same tree later with npm ci, pnpm install --frozen-lockfile or yarn install --immutable. For an interactive list you can select from, npx npkill scans a folder and deletes the node_modules you pick.

What should I not delete?

Does clearing caches speed up my Mac?

No. It frees disk space and fixes the occasional corrupted download. The next install or build is slower while the cache refills, and offline installs stop working until it does.

Review developer caches from the menu bar

WTMemory scans supported developer cache locations, including the npm, pnpm, Yarn, Bun, Cargo and Gradle caches, and shows each with a description and estimated size. You can reveal any item in Finder first. Inspection is free.

With Pro, you pick individual caches, review the consequences, and WTMemory moves them to the Trash. Nothing is selected automatically and nothing is permanently deleted; emptying the Trash is your decision. It works on those caches only: source code is excluded, and your projects, including their node_modules, are kept out of cleanup, so use the find command above for those. Close running package managers and builds first. WTMemory runs on macOS 12 and later, on Apple Silicon and Intel; Pro is $9 USD once for up to three Macs, with a seven-day trial.

Download WTMemory

FAQ

Is it safe to clear the npm cache?

Yes. The npm cache is a content-addressed copy of downloaded packages. Clearing it never breaks installed projects; the next install downloads packages again and offline installs stop working until it refills.

Why does npm cache clean need --force?

Since npm 5 the cache verifies itself and repairs corruption, so npm treats clearing it as unnecessary and asks you to confirm with --force. npm cache verify is the gentler option.

Will deleting the pnpm store break my projects?

pnpm store prune only removes packages no project references, so it is safe. Deleting the whole store does not corrupt existing node_modules, because files are hard links, but the next pnpm install has to download everything again.

Does clearing caches make my Mac faster?

No. It frees disk space. The next installs and builds are slower while the caches refill.

What is usually bigger, the caches or node_modules?

On machines with many projects, node_modules folders and Rust target folders inside projects usually add up to more than the global caches. Use find with du to list them.

Related guides

Full WTMemory guide and license help