ClearDisk -- Free macOS Developer Cache Cleaner

Ruby, Gems & Bundler Cache Cleanup on Mac — Reclaim 2-15GB+

Updated March 2025 -- Covers system Ruby, rbenv, chruby, RubyGems, Bundler, Rails, and CocoaPods gems -- 10 min read

Ruby development on macOS involves multiple layers of disk usage that accumulate silently: installed Ruby versions (each 150-500MB), gem caches, Bundler vendor directories, documentation files, and native extension build artifacts. For developers working on Rails projects, iOS apps (CocoaPods uses Ruby), or managing multiple Ruby versions via rbenv, it's common to find 2-15GB+ of Ruby-related files on your Mac.

This guide covers every Ruby-related disk consumer on macOS, with exact commands to audit and clean each one safely.

Table of Contents 1. Quick Audit — Where Is Your Ruby Disk Space Going? 2. RubyGems Cache — Downloaded .gem Files 3. Cleaning Old Gem Versions 4. Gem Documentation — The Silent Space Consumer 5. Bundler Cache & Vendor Directories 6. Multiple Ruby Versions (rbenv / chruby / rvm) 7. Native Extension Build Artifacts 8. Rails-Specific Cleanup 9. CocoaPods & Ruby — The iOS Connection 10. Automate Ruby Cleanup 11. Ruby Cleanup Cheatsheet 12. FAQ

1. Quick Audit — Where Is Your Ruby Disk Space Going?

#!/bin/bash
echo "=== Ruby Disk Usage Audit ==="
echo ""

echo "--- System Ruby ---"
du -sh /Library/Ruby 2>/dev/null || echo "  Not found"

echo ""
echo "--- rbenv ---"
du -sh ~/.rbenv/versions 2>/dev/null || echo "  rbenv versions not found"
du -sh ~/.rbenv/cache 2>/dev/null || echo "  rbenv cache not found"
ls ~/.rbenv/versions 2>/dev/null | while read v; do
    du -sh ~/.rbenv/versions/$v
done

echo ""
echo "--- chruby / ruby-install ---"
du -sh ~/.rubies 2>/dev/null || echo "  chruby not found"
du -sh ~/src 2>/dev/null || echo "  ruby-install src not found"

echo ""
echo "--- rvm ---"
du -sh ~/.rvm 2>/dev/null || echo "  rvm not found"

echo ""
echo "--- RubyGems Cache ---"
gem_cache=$(gem environment gemdir 2>/dev/null)/cache
du -sh "$gem_cache" 2>/dev/null || echo "  Gem cache not found"

echo ""
echo "--- Bundler Cache ---"
du -sh ~/.bundle/cache 2>/dev/null || echo "  Bundler global cache not found"
du -sh ~/Library/Caches/com.apple.developers.bundler 2>/dev/null || echo "  No macOS Bundler cache"

echo ""
echo "--- vendor/bundle directories ---"
echo "  Scanning common project locations..."
find ~/Developer ~/Projects ~/code ~/workspace 2>/dev/null -name "vendor" -type d -maxdepth 4 | while read dir; do
    if [[ -d "$dir/bundle" ]]; then
        size=$(du -sh "$dir/bundle" 2>/dev/null | awk '{print $1}')
        echo "  $size  $dir/bundle"
    fi
done | sort -hr | head -10

echo ""
echo "--- Gem Documentation ---"
du -sh "$(gem environment gemdir 2>/dev/null)/doc" 2>/dev/null || echo "  Gem docs not found"

echo ""
echo "=== Quick Estimate ==="
total=0
for d in ~/.rbenv/versions ~/.rbenv/cache ~/.rvm ~/.rubies; do
    if [[ -d "$d" ]]; then
        size=$(du -sk "$d" 2>/dev/null | awk '{print $1}')
        total=$((total + size))
    fi
done
gem_dir=$(gem environment gemdir 2>/dev/null)
if [[ -d "$gem_dir" ]]; then
    size=$(du -sk "$gem_dir" 2>/dev/null | awk '{print $1}')
    total=$((total + size))
fi
echo "Estimated Ruby disk usage: $((total / 1024)) MB"
Tip: iOS/macOS developers who use CocoaPods have Ruby installed even if they're not "Ruby developers." Check for rbenv or system Ruby gem directories — CocoaPods dependencies can consume 500MB-2GB.

2. RubyGems Cache — Downloaded .gem Files

Every time you install a gem, RubyGems downloads the .gem file and caches it. These cached files are never automatically cleaned up:

# Find your gem cache directory
gem environment gemdir
# Example: ~/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0

# Check cache size
du -sh "$(gem environment gemdir)/cache"

# List cached gems by size
ls -lhS "$(gem environment gemdir)/cache" | head -20

# Count cached gems
ls "$(gem environment gemdir)/cache" | wc -l

Clean the Gem Cache

# Remove all cached .gem files (safe — gems are already installed)
rm -rf "$(gem environment gemdir)/cache"/*

# Or use gem cleanup to remove old versions AND their caches
gem cleanup --dryrun    # Preview what would be removed
gem cleanup             # Actually remove old gem versions

If you have multiple Ruby versions via rbenv, each has its own cache:

# Clean gem caches for ALL rbenv Ruby versions
for version_dir in ~/.rbenv/versions/*/; do
    cache="$version_dir/lib/ruby/gems/*/cache"
    for c in $cache; do
        if [[ -d "$c" ]]; then
            size=$(du -sh "$c" 2>/dev/null | awk '{print $1}')
            echo "Cleaning $c ($size)"
            rm -rf "$c"/*
        fi
    done
done

3. Cleaning Old Gem Versions

When gems are updated, old versions remain installed. The gem cleanup command removes these:

# Preview which gems would be removed
gem cleanup --dryrun

# Example output:
# Cleaning up installed gems...
# Dry Run Mode: Would uninstall nokogiri-1.15.4
# Dry Run Mode: Would uninstall rails-7.0.8
# Dry Run Mode: Would uninstall bundler-2.4.22
# ...

# Actually clean up (removes old versions, keeps latest)
gem cleanup

# Remove a specific gem entirely
gem uninstall gem_name

# Remove a specific version
gem uninstall gem_name --version '1.0.0'

# List all installed gems with sizes
gem list | while read line; do
    name=$(echo "$line" | awk '{print $1}')
    dir="$(gem environment gemdir)/gems/$name"
    if [[ -d "$dir" ]]; then
        du -sh "$dir" 2>/dev/null
    fi
done | sort -hr | head -20
Warning: Don't run gem cleanup if you have projects that depend on specific older gem versions without Bundler. With Bundler (which most modern projects use), gem cleanup is safe because Bundler manages exact versions via Gemfile.lock.

4. Gem Documentation — The Silent Space Consumer

By default, gem install generates RDoc and ri documentation for every gem. Most developers never use this documentation (they use online docs instead), but it consumes significant space:

# Check documentation size
du -sh "$(gem environment gemdir)/doc"

# List documentation by size
du -sh "$(gem environment gemdir)/doc"/* | sort -hr | head -20

# Remove all gem documentation
rm -rf "$(gem environment gemdir)/doc"/*

Disable Documentation Forever

# Create or edit ~/.gemrc to skip documentation on future installs
echo "gem: --no-document" >> ~/.gemrc

# Verify
cat ~/.gemrc
# Should contain: gem: --no-document

# This skips both RDoc and ri documentation for all future gem installs
# Saves ~30-50% of gem install disk usage
Highly recommended: Adding gem: --no-document to your ~/.gemrc is one of the simplest ways to reduce Ruby disk usage going forward. Most developers get their documentation from rubydoc.info or docs.ruby-lang.org instead.

5. Bundler Cache & Vendor Directories

Bundler manages per-project gem dependencies and maintains its own caching system:

5.1 Global Bundler Cache

# Check Bundler's global cache
du -sh ~/.bundle/cache 2>/dev/null

# Bundler config location
ls -la ~/.bundle/

# Clean Bundler's cache
bundle cache --all    # In a project — caches gems in vendor/cache
bundle clean          # Remove unused gems from the current bundle
bundle clean --force  # Force removal, even if gems are still in Gemfile

5.2 Vendor/Bundle Directories 500MB-3GB per project

If you use bundle install --path vendor/bundle (or have the BUNDLE_PATH set), gems are installed per-project. This is great for isolation but can use massive disk space across many projects:

# Find all vendor/bundle directories
find ~ -path "*/vendor/bundle" -type d -maxdepth 6 2>/dev/null | while read dir; do
    du -sh "$dir" 2>/dev/null
done | sort -hr

# Clean vendor/bundle in the current project
cd /path/to/project
rm -rf vendor/bundle
bundle install  # Reinstalls from cache or network

# Check if Bundler is configured to use vendor/bundle globally
bundle config path
# If set, consider unsetting it to use the default gem directory instead:
bundle config unset path

5.3 Bundler Tmp and Build Artifacts

# Bundler sometimes leaves build artifacts
find ~ -path "*/.bundle/tmp" -type d -maxdepth 5 2>/dev/null -exec du -sh {} \;

# Clean project-level Bundler temp files
find ~/Developer -name ".bundle" -type d -maxdepth 4 2>/dev/null | while read dir; do
    if [[ -d "$dir/tmp" ]]; then
        du -sh "$dir/tmp"
        rm -rf "$dir/tmp"
    fi
done

6. Multiple Ruby Versions (rbenv / chruby / rvm)

Each installed Ruby version is 150-500MB. With gems installed per-version, the total per Ruby version often reaches 500MB-2GB.

6.1 rbenv

# List installed versions with sizes
for v in ~/.rbenv/versions/*/; do
    du -sh "$v"
done

# See which version you're currently using
rbenv version

# List all installed versions
rbenv versions

# Remove old versions you no longer need
rbenv uninstall 3.1.4
rbenv uninstall 3.2.2

# Clean rbenv's download cache
du -sh ~/.rbenv/cache 2>/dev/null
rm -rf ~/.rbenv/cache/*

# Clean rbenv shims (harmless)
rbenv rehash

6.2 chruby / ruby-install

# List installed versions
ls -la ~/.rubies/

# Check sizes
du -sh ~/.rubies/*

# Remove old versions
rm -rf ~/.rubies/ruby-3.1.4

# ruby-install keeps source tarballs
du -sh ~/src 2>/dev/null
ls ~/src/ 2>/dev/null

# Clean source tarballs
rm -rf ~/src/ruby-*

6.3 rvm

# RVM is known for heavy disk usage
du -sh ~/.rvm

# List installed Rubies
rvm list

# Remove old versions
rvm remove 3.1.4

# Clean rvm caches and archives
rvm cleanup all

# Clean downloaded source archives
du -sh ~/.rvm/archives
rm -rf ~/.rvm/archives/*

# Clean rvm logs
rm -rf ~/.rvm/log/*
Recommendation: If you're using rvm and disk space is a concern, consider migrating to rbenv or chruby. rvm is significantly heavier (often 1-3GB for the tool itself plus installed rubies). rbenv is much leaner.

7. Native Extension Build Artifacts

Gems with native C extensions (like nokogiri, ffi, pg, mysql2) leave build artifacts behind:

# Find native extension build logs and artifacts
find "$(gem environment gemdir)/extensions" -type f 2>/dev/null | head -20
du -sh "$(gem environment gemdir)/extensions" 2>/dev/null

# Gem build temp files
find "$(gem environment gemdir)/gems" -name "tmp" -type d 2>/dev/null | while read dir; do
    du -sh "$dir"
done

# Clean gem build artifacts while keeping gems functional
# This rebuilds native extensions from source
gem pristine --all --only-executables

# Clean all and rebuild (takes longer but more thorough)
gem pristine --all

8. Rails-Specific Cleanup

Rails projects accumulate additional disk usage beyond gems:

# Rails log files (can grow to gigabytes if not rotated)
du -sh log/ 2>/dev/null
# Clean logs
rake log:clear
# Or manually
cat /dev/null > log/development.log
cat /dev/null > log/test.log

# Rails tmp directory (caches, pids, sessions)
du -sh tmp/ 2>/dev/null
rake tmp:clear

# Asset precompilation artifacts
du -sh public/assets 2>/dev/null
rake assets:clobber

# Spring process files (Rails process manager)
du -sh tmp/pids 2>/dev/null
spring stop

# Bootsnap cache
du -sh tmp/cache/bootsnap 2>/dev/null
rm -rf tmp/cache/bootsnap

# ActiveStorage local files (development uploads)
du -sh storage/ 2>/dev/null
# Be careful — this is actual user-uploaded content in development

Find All Rails Projects and Their Log Sizes

find ~/Developer -name "Gemfile" -maxdepth 4 2>/dev/null | while read gemfile; do
    project_dir=$(dirname "$gemfile")
    if [[ -f "$project_dir/config/environment.rb" ]]; then
        log_size=$(du -sk "$project_dir/log" 2>/dev/null | awk '{print $1}')
        tmp_size=$(du -sk "$project_dir/tmp" 2>/dev/null | awk '{print $1}')
        total=$(( (log_size + tmp_size) / 1024 ))
        if [[ $total -gt 10 ]]; then
            echo "${total}MB  $(basename $project_dir)  (log:${log_size}K tmp:${tmp_size}K)"
        fi
    fi
done | sort -hr

9. CocoaPods & Ruby — The iOS Connection

CocoaPods is a Ruby gem, so iOS/macOS developers have Ruby gem overhead even if they don't consider themselves Ruby developers:

# Check CocoaPods gem size
gem contents cocoapods 2>/dev/null | head -5
du -sh "$(gem environment gemdir)/gems/cocoapods-"* 2>/dev/null

# CocoaPods has many dependencies — check total
gem dependency cocoapods --pipe 2>/dev/null | wc -l

# If you've switched to Swift Package Manager and no longer need CocoaPods:
gem uninstall cocoapods
gem uninstall cocoapods-core cocoapods-downloader cocoapods-plugins cocoapods-search cocoapods-trunk
gem cleanup

# Also clean CocoaPods-specific directories (covered in our CocoaPods guide)
# rm -rf ~/Library/Caches/CocoaPods
# rm -rf ~/.cocoapods/repos
See also: Our dedicated CocoaPods Cache Cleanup Guide covers CocoaPods-specific directories in much more detail.

10. Automate Ruby Cleanup

#!/bin/bash
# ruby-cleanup.sh — Safe Ruby cache cleanup for macOS

set -euo pipefail
echo "💎 Ruby Cache Cleanup — $(date)"
echo "================================="
freed=0

cleanup() {
    local path="$1"
    local desc="$2"
    if [[ -d "$path" ]]; then
        size=$(du -sk "$path" 2>/dev/null | awk '{print $1}')
        if [[ $size -gt 0 ]]; then
            echo "  Cleaning $desc: $((size/1024))MB"
            rm -rf "$path"/*
            freed=$((freed + size))
        fi
    fi
}

# Gem caches for all rbenv versions
echo ""
echo "--- Gem Caches ---"
for cache_dir in ~/.rbenv/versions/*/lib/ruby/gems/*/cache; do
    if [[ -d "$cache_dir" ]]; then
        cleanup "$cache_dir" "$(echo $cache_dir | grep -oP 'versions/[^/]+')"
    fi
done

# Gem documentation for all versions
echo ""
echo "--- Gem Documentation ---"
for doc_dir in ~/.rbenv/versions/*/lib/ruby/gems/*/doc; do
    if [[ -d "$doc_dir" ]]; then
        cleanup "$doc_dir" "gem docs $(echo $doc_dir | grep -oP 'versions/[^/]+')"
    fi
done

# rbenv download cache
echo ""
echo "--- rbenv Cache ---"
cleanup ~/.rbenv/cache "rbenv download cache"

# Bundler cache
echo ""
echo "--- Bundler Cache ---"
cleanup ~/.bundle/cache "Bundler global cache"

# Clean old gem versions (for current Ruby)
echo ""
echo "--- Old Gem Versions ---"
echo "  Running gem cleanup..."
gem cleanup 2>/dev/null || true

echo ""
echo "================================="
echo "Total freed: $((freed/1024))MB"
echo ""
echo "Tip: Add 'gem: --no-document' to ~/.gemrc to prevent doc generation"

11. Ruby Cleanup Cheatsheet

Component Typical Size Cleanup Command Safe?
Gem Cache (.gem files) 200MB-2GB rm -rf $(gem env gemdir)/cache/* Yes
Old Gem Versions 500MB-3GB gem cleanup Yes (with Bundler)
Gem Documentation 200MB-1GB rm -rf $(gem env gemdir)/doc/* Yes
vendor/bundle per project 500MB-3GB rm -rf vendor/bundle Yes (re-bundle)
Unused Ruby versions 300MB-2GB each rbenv uninstall X.X.X Check project .ruby-version
rbenv download cache 50-500MB rm -rf ~/.rbenv/cache/* Yes
rvm archives 100MB-1GB rm -rf ~/.rvm/archives/* Yes
Rails logs 10MB-5GB rake log:clear Yes
Rails tmp/cache 50-500MB rake tmp:clear Yes
Bundler tmp 10-200MB rm -rf .bundle/tmp Yes

12. FAQ

Is it safe to remove the gem cache directory?

Yes. The cache directory ($(gem environment gemdir)/cache) contains only downloaded .gem files — copies of what was downloaded from rubygems.org. Your installed gems (in the gems/ directory) are unaffected. If you ever need these cached files again (for gem pristine or offline installs), they'll be re-downloaded automatically.

Will gem cleanup break my projects?

Not if you use Bundler (which all modern Ruby projects do). gem cleanup removes old versions of gems, keeping only the latest. Your projects' Gemfile.lock specifies exact versions, and bundle install will re-install any needed versions. Run gem cleanup --dryrun first to preview what would be removed.

How much space does disabling gem documentation save?

Adding gem: --no-document to ~/.gemrc typically saves 30-50% of total gem installation size going forward. For a fresh Ruby install with Rails and common gems, that's often 200-500MB saved. For existing installations, you can remove the doc directory to reclaim the space retroactively.

Should I use rbenv or rvm?

For disk space efficiency, rbenv is significantly lighter than rvm. rvm installs a lot of supporting infrastructure (~1-3GB baseline), while rbenv is minimal. chruby is even lighter still. If you're only managing a few Ruby versions and disk space is a concern, rbenv or chruby are the better choices. See our Version Manager Cleanup Guide for detailed rbenv cleanup instructions.

Can I remove system Ruby on macOS?

macOS Sonoma and later no longer ship with a system Ruby. If you're on an older macOS version, don't modify or remove the system Ruby (/usr/bin/ruby) — it's used by system tools. Instead, install Ruby via rbenv or chruby and manage disk space for those separately. System Ruby's gems at /Library/Ruby/Gems can be cleaned with sudo gem cleanup, but be cautious about removing gems that macOS utilities depend on.

Can ClearDisk monitor Ruby and gem disk usage?

Yes! ClearDisk is a free macOS menu bar app that monitors 44+ developer cache locations in real time, including RubyGems cache directories and Bundler storage. It shows you at a glance how much space your development tools are consuming. Download it from the GitHub repository.

Monitor All Your Developer Caches Automatically

ClearDisk lives in your menu bar and monitors 44+ cache paths — Ruby gems, Bundler, Python, Node, Xcode, Docker, and more — so you always know where your disk space is going.

Get ClearDisk — Free & Open Source

Related guides:

About ClearDisk: A free, open-source macOS menu bar utility that monitors developer cache disk usage in real time. Supports 44+ cache paths including Xcode, node_modules, CocoaPods, Gradle, Docker, pip, Cargo, Homebrew, and more. View on GitHub.