Fixing Low Storage Space on Mac as a Developer

2 min read

  • technical
  • mac
  • terminal

Published on June 30, 2024

If you're like me, one day you got the dreaded message, "Your Mac is running low on disk space." The surprising thing is that I don't do anything other than develop on my Mac, so this was unexpected.


Usually, when this happens, I'd suspect node_modules, and I'd go after it using npkill:

npx npkill

# Then delete all the unwanted node_modules folders

I've deleted node_modules worth 3 gigs once, so it's always a good idea to do this periodically if you deal with many repos.

But this time, even after deleting all the node_modules, the disk was still low, so I decided to dig deeper. In Windows, there's an interesting tool called WinDirStat that visualizes how your storage is distributed, giving you a clear-cut idea of what's taking up space. I haven't found an open-source WinDirStat alternative for Mac yet, so I turned to the good old terminal.

I ran the following command on my root folder:

du -h . | grep "G\t" | sort

This command displays all the files and folders larger than 1 GB. I'd do this recursively through each large folder to determine which files are taking up the most space.

Most of the large files were under ~/Library, and I noticed I had a huge cache folder. Upon inspecting it, I realized that the Yarn cache was taking up almost 25 GB of space! Similarly, the Cypress folder was taking over 5 GB.

So, I ran the following commands:

yarn cache clean

npx cypress cache prune

Apart from this, since I work with Ruby on Rails, I noticed that the gems folder was also massive. It had gems from older versions of Ruby that I didn't use anymore. So, I decided to clean up the gems:

gem cleanup

After all these fixes, I cleaned up almost 35 GB of space, which was massive for me.