Cleaning up macOS bloat

Freeing up disk space on macOS, particularly caches that usually never get purged.

Development packaging caches

Ruby

~/.gem contains gem-installed package information for each version of Ruby

rm -rf ~/.gem

Python

~/Library/Caches/pip contains packages cached by pip

~/Library/Caches/pipenv contains packages cached by pipenv

Java

~/.m2/repository contains Java packages (.jar files) and Maven project information (.pom files) for dependencies installed by Maven or related package managers, such as Leiningen:

rm -rf ~/.m2/repository/

Note that ~/.m2/settings.xml contains user customizations and you probably don’t want to delete it.

~/.ivy2/cache contains Java packages and Ivy artifact information for dependencies installed by Apache Ant or related package managers, such as sbt (Scala Simple Built Tool):

rm -rf ~/.ivy2/cache/

~/.sbt contains plugins and other caches used by sbt:

rm -rf ~/.sbt/

~/Library/Caches/Coursier contains Java packages installed by Coursier (Scala):

rm -rf ~/Library/Caches/Coursier/

~/Library/Application Support/Java contains all previously installed Java packages

rm -rf ~/Library/"Application Support"/Java/*/

Haskell

~/.cabal/setup-exe-cache contains cabal executables for OS X

rm -rf ~/.cabal/setup-exe-cache

~/.cabal/packages contains cached index and cabal-installed tarballs

rm -rf ~/.cabal/packages/

~/.stack/indices contains cached index and stack-installed tarballs

rm -rf ~/.stack/indices

~/.stack/setup-exe-cache contains cabal executables for OS X

rm -rf ~/.stack/setup-exe-cache

~/.stack/snapshots contains ghc tooling, binaries, documentation

rm -rf ~/.stack/snapshots

JavaScript

~/.bower contains Bower’s cache of git repositories

rm -rf ~/.bower ~/.cache/bower

~/.node-gyp contains gyp build files for each version of Node.js

rm -rf ~/.node-gyp

~/.npm contains the npmjs repository cache

npm cache clean --force

iOS/macOS

~/.cocoapods contains the CocoaPods cache

rm -rf ~/.cocoapods

~/Library/Caches/org.carthage.CarthageKit contains Carthage’s intermediate build files (in addition to the ./Carthage/ directory in your actual project):

rm -rf ~/Library/Caches/org.carthage.CarthageKit

Miscellaneous

~/.vagrant.d/boxes contains Vagrantfile box information

rm -rf ~/.vagrant.d/boxes

~/.cache/youtube-dl contains “sigfunc” data that youtube-dl keeps around (or used to?)

youtube-dl --rm-cache-dir

/usr/local/texlive/*/tlpkg/backups contains TexLive package manager backups

tlmgr backup --clean=0 --all

spaCy downloads raw data to a cache directory but doesn’t clean up after unpacking. This removes just the downloaded archives, not what spaCy actually uses:

rm -rf /usr/local/lib/python2.7/site-packages/spacy/data/__cache__

Homebrew hoards the binary “bottle” or source archive/tarball for every package you’ve ever brew install‘ed. Even when consistently using brew upgrade --cleanup or brew cleanup, Homebrew keeps the latest version around. Assuming that anything you’ve had installed for a while has been tested well enough, it should be reasonably safe to delete everything in the cache that’s at least 31 days old:

brew cleanup --prune=31

Homebrew-Cask exhibits the same hoarding tendency. To clean out the cask cache:

brew cask cleanup

/var/db/receipts (-> /private/var/db/receipts) contains “bill of materials” files for all packages using the standard installer method (*.pkg files). Some of these are massive, like texlive’s, and the old ones aren’t always cleaned out when a new version is installed in-place.

/var/db/diagnostics is another destination that seems rarely cleared out.

Browsers

Firefox

  1. Open “Preferences” (+,)
  2. Type “cache” in search box
    • Or, Navigate to “Privacy & Security” (3rd item out of 4 in left navigation bar) → scroll about a page down to “Cached Web Content”
  3. Click “Clear Now”

Brave

  1. Open “Preferences” (+,)
  2. Navigate to “🔒 Security” (4th out of 10 items in left navigation bar)
  3. Click “Clear Browsing Data Now…”
  4. Toggle “Cached images and files” to on (others can be off)
  5. Click “Clear”

Chrome

  1. ++ (command+shift+delete)
    • Or, Navigate to <chrome://settings/clearBrowserData>
    • Or, Open “Preferences” (+,)
      • Search for “cache” → click bottom option “Clear browsing data”
      • Or, Scroll to bottom → click “Advanced ⏷” → scroll to bottom of “Privacy and security” section → click bottom option “Clear browsing data”
  2. In “Time range” drop-down menu, choose “All time”
  3. Check “Cached images and files” (others can be off)
  4. Click “CLEAR DATA”

Safari

Apparently there’s no option to clear the cache but keep cookies and history.

  1. Preferences (+,)
  2. Navigate to “✋ Privacy” (7th out of 10 items in top navigation bar)
  3. Click “Manage Website Data…”
  4. Wait until it loads, LOL.
  5. Click “Remove All”

Spotify

Spotify caches gobs of data in an absolutely impenetrable format.

rm -rf ~/Library/Caches/com.spotify.client/Data/

macOS’s built-in “Storage Management.app”

As of macOS Sierra (10.12), Apple provides a built-in cleanup (or at least, usage overview) application, called “Storage Management”. Alfred can’t find it, but Spotlight will, or you can open it directly:

open '/System/Library/CoreServices/Applications/Storage Management.app'

Or through the macOS desktop:

  1. Click “” in the menu bar to open the “Apple menu”
  2. Click “About This Mac”
  3. Navigate to the “Storage” tab
  4. Next to “Macintosh HD” (or whatever your drive happens to be named), and click “Manage…”

On the “💡 Recommendations” page, in the “Reduce Clutter” section, click “Review Files”.

This simply lists all the large files (> 50 MB) on your drive that macOS has identified as “Documents”, sorted from largest to smallest. It’s unclear exactly what qualifies for “Large File” status, but it appears that all file types are candidates This isn’t terribly special, but having a single flat list of all the large files is handy, and it immediately refreshes when you delete files (even from a separate Finder window), which is nice.

There is also a “Downloads” listing (apparently limited to ~/Downloads, not just anything with a URL in its kMDItemWhereFroms xattr), which is less helpful.

The “File Browser” shows the hierarchical directory structure for everything in the ~/ directory, sorted by size, providing an overview of what’s taking up the most space.

Xcode

DerivedData/ contains the intermediate build files for Xcode projects. Can also be deleted from within Xcode → “Window” → “Projects” → …select a project → “Delete…”

rm -rf ~/Library/Developer/Xcode/DerivedData/*

iOS DeviceSupport/ contains symbols for each architecture of devices that have been connected. Safe to delete all of them, and sane to delete all but the current deployment target(s).

trash ~/Library/Developer/Xcode/"iOS DeviceSupport"/*/

CoreSimulator/Devices contains partial per-Device information for simulation. These are easy to replace, so it’s safe to delete the ones you aren’t using, but they don’t take up that much space anyway (~500MB total). Can also be deleted from within Xcode → “Window” → “Devices and Simulators” → …right click a device → “Delete”

trash ~/Library/Developer/CoreSimulator/Devices/*/

Less drastically, you can manage your simulators with simctl (ref); to list them:

xcrun simctl list devices

Then, to remove the “unavailable” ones:

xcrun simctl delete unavailable

Profiles/Runtimes contains actual simulator runtimes, which can weigh in at 2GB+. These can be reinstalled any time within Xcode → Preferences → “Components” → “Simulators” → …click the download icon

trash /Library/Developer/CoreSimulator/Profiles/Runtimes/*/

Mac OS X install extras

Dictionaries for other languages:

trash /Library/Dictionaries/*{Chinese,Duden,Dutch,French,German,
                              Hindi,Italian,Korean,Norwegian,
                              Portuguese,Russian,Sanseido,
                              Spanish,Swedish,Thai,Turkish}*