Free up disk space on a Mac (developer edition)

Caches, old dependencies and Docker images quietly eat tens of gigabytes. Find them and clean them safely.

5 min6 stepsmacOS

  1. See how full the disk is

    Check the Avail column for /.

    df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda1        98G   61G   33G  65% /
  2. Find what’s big in your home folder

    Run this from ~ to see the biggest folders.

    du -sh * | sort -h
    4.0K	README.md
    120M	dist
    1.4G	node_modules
  3. Clean Homebrew

    Removes old versions and the download cache.

    brew cleanup --prune=all
  4. Clean Docker

    Check first, then prune unused images and build cache.

    docker system df
    TYPE            TOTAL   ACTIVE   SIZE      RECLAIMABLE
    Images          23      4        9.8GB     7.1GB (72%)
    Build Cache     188     0        3.2GB     3.2GB
  5. Delete old node_modules

    Run from your projects folder. Each project reinstalls with npm install.

    find . -name "node_modules" -type d -prune -exec rm -rf {} +

    Deletes folders permanently. Run it from your projects folder, not from / or ~.

  6. Clear the npm cache

    Often several gigabytes.

    npm cache clean --force

More guides