All guides

Developer

How to clean node_modules and Docker cache on a Mac

Developer tools are among the biggest space users on a Mac. Most of it can be rebuilt. Here is how to find it and what to be careful with.

node_modules

A node_modules folder is rebuilt by running npm install (or pnpm install or yarn) again, so it is safe to delete in projects you are not working on. To list the folders and their sizes, run:

find ~ -name node_modules -type d -prune -exec du -sh {} + 2>/dev/null | sort -h

Delete the ones in old projects, and keep the ones you need offline.

Package-manager caches

  • npm: npm cache clean --force
  • pnpm: pnpm store prune removes packages no project uses.
  • Yarn: yarn cache clean
  • Homebrew: brew cleanup removes old versions and downloads.

These caches are re-downloaded when needed, so the cost is a slower next install.

Docker

Docker Desktop stores images, containers and volumes in one large disk image. First see what uses space:

docker system df

Then remove what you do not need:

  • docker builder prune clears the build cache.
  • docker image prune removes dangling images; add -a to remove all unused images.
  • docker system prune removes stopped containers, unused networks and dangling images.

Be careful with volumes. Volumes can hold database data. docker system prune --volumes deletes unused volumes for good. Check docker volume ls first.

Why Docker.raw does not shrink

Deleting images inside Docker frees space in Docker’s disk image, but the file on your Mac can stay large until Docker Desktop reclaims it. Restarting Docker Desktop or using its disk-usage settings usually shrinks it.

A safe order

  1. Measure first: docker system df and the find command above.
  2. Delete node_modules in inactive projects.
  3. Clear package caches.
  4. Prune Docker build cache and dangling images before touching volumes.

sysZivo’s developer filters (Node.js, Docker, virtual machines and more) show these on the storage map with sizes, so you can see which projects hold the most before you run anything. Related: delete Xcode DerivedData safely and clear cache on Mac safely.

Questions people ask

Is it safe to delete node_modules?

Yes. Run npm install, pnpm install or yarn in the project to restore it. Keep it if you need to work offline.

How do I free space from Docker on a Mac?

Run docker system df to see usage, then docker builder prune and docker image prune. Check volumes before pruning them, because they can hold data.

Why does Docker.raw stay big after I delete images?

The disk image on your Mac does not always shrink right away. Restarting Docker Desktop or reclaiming space in its settings usually helps.

Try it on your Mac

Free to scan and explore. Cleaning needs Pro: €19.99 a year, or a 14-day trial for €1.

Download for Mac

Original writing by the sysZivo team. Apple, macOS, Mac, MacBook, Xcode and Time Machine belong to Apple Inc. Docker, Node.js and npm belong to their owners and are named only to describe compatibility. sysZivo is not affiliated with or endorsed by them. See Brand & trademarks.