Installing or updating an app (ahem, ahem XCode…) on macOS is sometimes surprisingly difficult because of missing disk space. In this blog post, I’ll describe various ways to quickly and safely clean vast amounts of storage on a Mac Book used for web development.
I’ve recently performed the same analysis and cleanup on my MacBook Pro. As a result, I’ve managed to free tens of GBs of storage and could finally update XCode to the newest version.
Analyze your disk usage
The program offers straightforward UI allowing you to at a glance examine your storage usage:
Let’s now discuss the lowest hanging fruits in reducing storage usage.
Remove redundant applications cache
On my computer the significant bulk of unnecessary data was in the
~/Library/Caches folder. I’ve noticed hundreds of MBs related to Yarn that I did not use for a year or so. Apparently, many applications are keen to cache data while neglecting to do the cleanup afterward.
You can thoroughly purge the cache using the following commands:
Alternatively, you can cherry-pick which cache folders to remove. I’ve been regularly doing the total cache cleanups for a couple of months now. Other than the temporary system slowdown, I did not notice any issues.
Obviously, the cache will rebuild itself over time. But it does not grow to the same size even after a more extended period. After removing over 30GB of cache, the
Caches folder size increased to only around 2GB after the week of regularly using the computer.
Remove old log files
I work mostly with Ruby on Rails on my desktop. While using Disk Inventory X, I’ve discovered that running the local tests continuously appends content to the
I can imagine other stacks similarly silently consuming the disk space. Disk Inventory X is invaluable in identifying and fixing such cases.
Reduce Docker disk space usage
Docker has a bad reputation for devouring large amounts of disk space. You can check how much of your disk space Docker has acquired so far by running:
docker images to see which images are taking up most of the disk space:
On my computer, I’ve had various versions of the
postgres image, each taking a considerable amount of space. You can remove the Docker image by running the following command:
From my experience, images usually take most of the disk space. However, if you’d like to do a more global cleanup including Docker containers, networks, volumes, and cache, use this command:
The total cleanup works for me because all my local Docker projects can be easily recreated using seed data. Make sure to double-check if you don’t have data that will be difficult to recover before removing a container or a volume.
Check out the Docker documentation to read more about other pruning commands.
A honorable mention - node_modules
A blog post about missing disk space would not be complete without dedicating a paragraph to everyone’s beloved
You can use this command to list all the top-level
node_modules folders together with their corresponding size:
If you don’t feel like cherry-picking which bloated dependencies to destroy, you can run the following command to get rid of them all:
Just watch out if you’re running it in a top-level (i.e., home) folder because it might remove some necessary system-level dependencies. But as long as you run it in your own
~/Programming folder it shouldn’t do any damage.
I hope those tips will help you to clean the vast amounts of disk space easily. Regularly checking the Disk Inventory X for unnecessary disk usage bloats is the a good practice that will help you keep your disk usage in order.