Cleaning disk space on macOS and MacBooks is represented by a brush Photo by Jan Kopřiva on Unsplash


Installing or updating an app (ahem, ahem XCode…) on macOS is sometimes astonishingly difficult because of missing disk blank space. In this blog postal service, I'll name various shipway to rapidly and safely clean immense amounts of storage on a Mac Book old for web development.

I've recently performed the same analysis and cleanup on my MacBook Pro. Equally a result, I've managed to free tens of GBs of warehousing and could at long last update XCode to the newest interlingual rendition.

Analyze your magnetic disk exercis

The best direction to identify where the mass of your storage space is allocated is to use Phonograph recording Inventory X application. Connected macOS, the simplest way to install information technology is to use the Home brew Cask.

            brewage              install              --cask              disk-inventory-x          

The program offers straightforward UI allowing you to at a glance examine your storage utilization:

Disk Invantory X UI

Let's now discuss the last hanging fruits in reducing storage custom.

Remove extra applications cache

On my figurer the probative bulk of unnecessary data was in the ~/Library/Caches booklet. I've detected hundreds of MBs connate Thread that I did not use for a twelvemonth some. Apparently, many applications are keen to cache data while neglecting to do the cleanup afterward.

macOS cache usage before cleanup

macOS cache utilization earlier cleaning

You can thoroughly purge the cache using the following commands:

                          cd              ~/Library/Caches              rm              -rf              *                      

Alternatively, you can cherry-pick which cache folders to hit. I've been regularly doing the total cache cleanups for a couple of months now. Former than the irregular system retardation, I did not notice any issues.

Obviously, the squirrel away will rebuild itself over fourth dimension. Only information technology does not maturate to the same size even after a to a greater extent extended period. After removing over 30GB of cache, the Caches pamphlet size increased to only some 2GB after the week of on a regular basis exploitation the computer.

macOS cache usage after cleanup

macOS cache usage a week after cleanup

Polish of nonagenarian log files

I work mostly with Ruby on Rails on my background. While using Disc Inventory X, I've discovered that lengthways the local tests endlessly appends cognitive content to the log/test.log file.

Overgrown Rails test log file

Overgrown Rails log file

I tooshie imagine otherwise stacks likewise taciturnly overwhelming the disk space. Disk Inventory X is invaluable in identifying and fixing much cases.

Cut down Longshoreman disc space usage

Docker funny meme

Docker has a bad reputation for devouring large amounts of disc space. You can check how much of your magnetic disc space Docker has nonheritable so far by running:

            docker organization              df              TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE Images          17        4         2.115GB   1.577GB              (74%)              Containers      6         1         138.4MB   0B              (0%)              Local Volumes   19        5         1.564GB   1.347GB              (86%)              Body-build Cache     0         0         0B        0B          

Now run docker images to see which images are taking up most of the saucer space:

            docker images  REPOSITORY     TAG          IMAGE ID      CREATED        SIZE pihole/pihole  latest       4642d275ab73  4 months ago   296MB postgres       11.8-chain  a7f73db0b977  6 months ago   156MB postgres       12.3-alpine  17150f4321a3  6 months ago   157MB postgres       9.6-chain of mountains   45f463e53bc1  6 months agone   36.1MB mountain         latest       a24bb4013296  7 months ago   5.57MB postgres       12.2-alpine  ae192c4d3ada  8 months ago   152MB postgres       9.6.17       529a7b20fb73  8 months ago   200MB postgres       11.6-alpine  89ae06c2ad76  11 months ago  152MB          

On my computer, I've had various versions of the postgres look-alike, each taking a considerable amount of space. You can dispatch the Longshoreman image by track the following command:

            docker rmi              -f              IMAGE_ID          

From my receive, images usually take almost of the disk space. However, if you'd like to do a to a greater extent global cleanup including Docker containers, networks, volumes, and cache, exercise this command:

            docker system prune              --volumes                      

The total cleanup whole works for me because all my local Docker projects buttocks be easily recreated using seed data. Make a point to threefold-check if you don't birth data that bequeath be difficult to recuperate before removing a container operating theater a volume.

Check out the Dock-walloper documentation to learn more about other pruning commands.

A mention - node_modules

A web log post about missing magnetic disc space would not be complete without dedicating a paragraph to everyone's beloved node_modules. Just a few modern JavaScript projects developed locally could easily consume tens of GBs of disk blank.

You can use this command to list all the top-level node_modules folders together with their corresponding size:

            find              .              -name              "node_modules"              -type              d              -prune              -exec              du              -sh              '{}'              +          

If you don't feel like cherry-picking which unhealthy dependencies to ruin, you can black market the following command to induce eliminate them all:

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

Just picke dead if you're running it in a top-tied (i.e., home) folder because it might remove some necessary scheme-level dependencies. But as long A you run it in your own ~/Programming brochure it shouldn't do any damage.

Summary

I hope those tips wish help you to clean the immense amounts of disk space easily. Regularly checking the Disk Inventory X for unnecessary phonograph recording usage bloats is the a good practice that will help you keep off your disk exercis in order.