跳到正文
DEV Community· prabhanjan sharma·· 47 分鐘前AI 評分54

2027 年開發者 Mac 釋放磁碟空間的最佳方法

Best Ways to Free Up Disk Space on a Developer Mac in 2027 (node_modules, Xcode, Docker)

AI 導讀

這份 2027 年指南整理開發者 Mac 釋放磁碟空間的方法,涵蓋 node_modules、Xcode、Docker、套件快取、Rust 和 Go 目錄,以及本機 AI 模型。

正文

Cover image for Best Ways to Free Up Disk Space on a Developer Mac in 2027 (node_modules, Xcode, Docker)

prabhanjan sharma

A developer Mac fills up in a very particular way. It is rarely photos; it is node_modules in fifty old projects, Xcode's DerivedData, simulators, Docker images and package caches. Here is the 2027 list of the best ways to get that space back, from one-line commands to free tools.

Disclosure: my team builds Free Mac (in the tools section). Every command here works without it.

First, measure

# biggest folders in your home directory, two levels deep
du -h -d 2 ~ 2>/dev/null | sort -h | tail -25

1. node_modules in old projects

# interactive: list every node_modules and delete with space bar
npx npkill

2. Package manager caches

npm cache clean --force
pnpm store prune
yarn cache clean
pip cache purge
brew cleanup -s && brew autoremove

3. Xcode: DerivedData, simulators and device support

rm -rf ~/Library/Developer/Xcode/DerivedData
xcrun simctl delete unavailable
# old device support folders, often several GB each
ls ~/Library/Developer/Xcode/iOS\ DeviceSupport

DerivedData rebuilds itself; deleting it is safe. Remove device support folders for iOS versions you no longer test on.

4. Docker

docker system df            # see what is using space
docker system prune -a      # remove stopped containers, unused images and networks
docker builder prune        # build cache

Docker Desktop keeps everything in one disk image, so the space only returns after a prune. You can also lower the disk limit in Settings, Resources.

5. Rust, Go and friends

cargo clean                 # inside each old Rust project; target/ folders get huge
go clean -cache -modcache

6. Local AI models

Ollama, LM Studio and Hugging Face keep multi-gigabyte models:

ollama list && ollama rm <model>
du -sh ~/.cache/huggingface ~/.lmstudio 2>/dev/null

Best tools for seeing the whole disk

Tool Price Best for
GrandPerspective Free Classic treemap of any folder
OmniDiskSweeper Free Sorted list, quick and simple
DaisyDisk Paid once Polished sunburst view
DevCleaner for Xcode Free Xcode-specific cleanup
Free Mac Free scan, key for cleaning One map of the whole drive, plus a developer scan that only counts build output when its manifest sits beside it

Free Mac scans and maps for free with no account; a key ($19.99 every six months) unlocks exact sizes, Reveal in Finder and moving files to the Trash. Nothing leaves the Mac.

A monthly routine

  1. npx npkill on your projects folder.
  2. Clear DerivedData and unavailable simulators.
  3. docker system prune -a.
  4. Run the caches block above.

FAQ

Is it safe to delete DerivedData? Yes. Xcode rebuilds it on the next build.

Why does System Data keep growing? On developer Macs it is mostly simulators, Docker's disk image, caches and local snapshots. Measure ~/Library and you will see which.

What was your biggest folder? Tell me in the comments.

來源:DEV Community · dev.to