Can You Delete the .gem Folder on Your Mac?

Yes, but read this firstDiskmack safety tier: Caution
~/.gem

Yes, you can delete ~/.gem, but know what you're giving up first. The folder holds Ruby gems installed for your user account plus the downloaded copies RubyGems keeps as a cache. Delete it and every affected project needs a fresh gem install or bundle install before it runs again. If you no longer write Ruby, that trade is usually worth taking.

What it is

~/.gem is the RubyGems home directory for your user account. Run gem install --user-install, or set user installs as the default in your ~/.gemrc, and the gem's code lands here instead of in the system Ruby folders. (On the Ruby that comes with macOS, plain gem install without sudo just fails with a permissions error, which is exactly why people end up using this folder.) RubyGems also keeps the .gem archive files it downloaded here, so a later reinstall can skip the network. Bundler can install here too, depending on how it's configured.

The folder grows one gem at a time and never tidies up after itself. Every version of every gem you've installed sticks around, including versions superseded years ago. On a Mac that has hosted a few Rails projects, several hundred megabytes is normal, and heavy setups can pass a couple of gigabytes. One caveat: if you use a version manager like rbenv or RVM, most of your gems actually live inside that manager's own directory, and ~/.gem is often small, holding little more than specs and cached archives.

Is it safe to delete?

This is a caution case, not a free pass. ~/.gem holds installed gems, not just cached downloads, so deleting it uninstalls every gem your user account installed there. Ruby itself is untouched and nothing in macOS depends on this folder, but any Ruby project or command line tool that used those gems will fail until you reinstall them. The fix is mechanical: run bundle install inside each project, or gem install for standalone tools, and everything comes back after a re-download.

Deleting makes sense if you've stopped working in Ruby, or the folder is full of gem versions from projects you trashed long ago. It's a poor move the day before a deploy, since reinstalling large native gems (nokogiri is the classic) means compile time on top of download time. Diskmack identifies ~/.gem automatically and marks it as a caution item, so you can see its real size before deciding.

How to check its size

In Finder: In Finder, choose Go > Go to Folder (or press Command-Shift-G), type ~/.gem and press Return. The folder is hidden, so Go to Folder is the reliable way in. It opens the folder itself, so click an empty patch of the window to make sure nothing is selected, then press Command-I. With nothing selected, Get Info reports on the folder you're viewing, and the size fills in after a few seconds.

In Terminal:

du -sh ~/.gem

The ~ expands to your home folder, so this measures /Users/<you>/.gem and prints one human-readable total.

How to clean it

  1. Check which Ruby you're on. Run which ruby in Terminal. If it prints /usr/bin/ruby, you're on the system Ruby and ~/.gem is where your user gems live. A path containing .rbenv or .rvm means a version manager keeps most of your gems elsewhere.
  2. Quit anything currently running Ruby: local Rails servers, Jekyll previews, watchers.
  3. Open your home folder in Finder (Go > Home, or Command-Shift-H), then press Command-Shift-Period so hidden files appear. The .gem folder shows up grayed out among the dotfiles.
  4. Drag .gem to the Trash. To be more surgical, open .gem, then ruby, and trash only the Ruby version folders you no longer use.
  5. Press Command-Shift-Period again to hide the dotfiles, and empty the Trash once you're comfortable.
  6. When a project next needs its gems, run bundle install in that project, or gem install <name> for individual tools.

If you installed command line tools with gem install --user-install, their executables live under ~/.gem/ruby/<version>/bin. They disappear with the folder and only come back when you reinstall each gem.

Will it come back?

Yes, at exactly the pace you use Ruby. Every gem install and every bundle install that targets your user directory writes here again, storing both the installed gem and its cached archive. Stop writing Ruby and the folder stays gone. Keep working on a Rails app and it will be back within days, roughly the size of that project's Gemfile.lock made real. That's fine. It means the folder is doing its job, and you can clear it again whenever old versions pile up.

Common questions

Will deleting ~/.gem break Ruby itself?

No. The Ruby that comes with macOS lives in /usr/bin, and version managers install their own copies in their own directories; neither is inside ~/.gem. You lose installed gems, not the language. Anything you removed comes back with gem install or bundle install.

I use rbenv or RVM. Does ~/.gem even matter?

Usually less than you'd expect. Version managers keep gems inside ~/.rbenv/versions or ~/.rvm/gems, so ~/.gem may hold only cached archives and spec files. Check its size first. If it's a few megabytes, cleaning it buys you nothing.

Can I delete just the cache instead of the whole folder?

Yes. ~/.gem/ruby/<version>/cache holds the downloaded .gem archives, which exist only to speed up reinstalls. Trashing just the cache keeps every installed gem working and still frees real space on gem-heavy setups.

Is there an official command that cleans this up?

There's no single wipe command, but gem cleanup uninstalls old versions of gems that have a newer version installed. It trims duplicates rather than clearing the folder, and it respects dependencies, so it's a gentler first step than deleting everything.

Related folders