Is it safe to delete node_modules, caches and build folders on a Mac?
One rule covers almost every case: if a tool can rebuild it from a file in your project, it's safe to delete. Updated 20 October 2026.
The rule
A folder is safe to delete when a tool recreates it from something you keep, such as package.json, Cargo.toml or Package.swift. It's not safe when it's the only copy of something, like your own files, a database, or a container's data.
Project folders
node_modules: reinstalled frompackage.jsonand the lockfile withnpm install(oryarn,pnpm install). You lose any hand edits made inside it, and you need a network connection to reinstall..next: Next.js build output, recreated bynext devornext build.targetnext toCargo.toml: Rust build output, recreated bycargo build. Often the biggest folder in a Rust project..buildnext toPackage.swift: Swift package build output, recreated byswift build.__pycache__: Python bytecode, written again the next time the code runs.
Check the folder sits next to its project file before you delete it. A folder called target or build somewhere else might be something else entirely.
Download caches
These hold packages so the next install doesn't download them again. Deleting them is safe and only costs download time. Each tool has its own clean command:
- npm:
~/.npm/_cacache, ornpm cache clean --force - Yarn:
~/Library/Caches/Yarn, oryarn cache clean - pip:
~/Library/Caches/pip, orpip cache purge - Homebrew:
~/Library/Caches/Homebrew, orbrew cleanup - CocoaPods:
~/Library/Caches/CocoaPods, orpod cache clean --all - Gradle:
~/.gradle/caches, downloaded again on your next build
Not safe to delete blindly
- Docker's disk image (
Docker.raw): it holds all your images, containers and volumes. Usedocker system pruneor Docker Desktop's cleanup instead. - Python virtual environments (
.venv): usually rebuildable, but only if every package is listed inrequirements.txtorpyproject.toml. - Maven's
~/.m2: may contain artifacts you built and installed locally that exist nowhere else. .gitfolders: your project's history.
Old projects first
The easy win is projects you haven't opened in months. Their node_modules and build folders can be hundreds of megabytes each, and you can rebuild them in a minute if you ever go back.


See it on your own Mac. CheckMac maps any folder or drive as a sunburst or treemap, and Suggested Cleanup lists the caches and build output a tool can rebuild, with what each one costs you. Scanning is free, and Suggested Cleanup is free for its first three runs.
More guides
- What is System Data on Mac, and how do you reduce it?
- How to delete Xcode DerivedData, simulators and device support files safely
- Looking for a CleanMyMac alternative?
- Mac storage almost full on a 256 GB Mac: what to do
- How to see what's taking up space on your Mac
- Free up disk space on a Mac for developers: a checklist
- Docker taking up space on Mac: Docker.raw explained
- How to delete local AI models on a Mac: Ollama, LM Studio and Hugging Face
- How to delete old iOS simulators and simulator runtimes
- Purgeable space on a Mac: what it is and how to clear it