Where apps hide your files
Where a gem lands depends on which Ruby is running, and a Mac can have several. One command, gem env, prints the exact folders for the Ruby your Terminal uses right now.
Ask RubyGems, because the answer changes with your Ruby:
gem env
Look at the INSTALLATION DIRECTORY and GEM PATHS lines. For the Ruby that ships with macOS, on the Mac used for this guide (Ruby 2.6.10 at /usr/bin/ruby), they were:
/Library/Ruby/Gems/2.6.0
/Users/<you>/.gem/ruby/2.6.0
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
The first is where gem install writes, the second is used with --user-install, and the third, inside the read-only system Ruby, holds the gems Apple ships with it. Print just the main folder with gem env gemdir. Open it in Finder with Go > Go to Folder (⇧⌘G), or use open "$(gem env gemdir)".
The location follows the Ruby, so first find out which one you are running:
which -a ruby
ruby -v
| Ruby | Where its gems go |
|---|---|
macOS system Ruby (/usr/bin/ruby) | /Library/Ruby/Gems/<ruby-version> for system installs, ~/.gem/ruby/<ruby-version> for --user-install. |
| rbenv | ~/.rbenv/versions/<version>/lib/ruby/gems/<ruby-version>, one set per Ruby. |
| RVM | ~/.rvm/gems/ruby-<version>, plus a separate @global set. |
| Homebrew Ruby | /opt/homebrew/lib/ruby/gems/<ruby-version> on Apple silicon, /usr/local/lib/ruby/gems/<ruby-version> with Intel Homebrew. Gem commands go in its bin subfolder. |
The rbenv and RVM rows follow each tool's one-folder-per-Ruby layout, and the Homebrew row comes from the ruby formula's own notes. None of the three had a Ruby installed on the Mac used here, so run gem env to confirm the folder for yours.
Inside the main gem folder you will find these subfolders, as seen in the system Ruby's folder on the Mac used here:
| Folder | What it holds |
|---|---|
gems | The installed gems, one folder per name and version, such as bundler-1.17.2. |
specifications | One small gemspec file per gem. |
cache | The downloaded .gem files. |
extensions | Compiled native extensions. |
doc | Generated documentation. |
build_info | Build records. |
Executables from gems go to the EXECUTABLE DIRECTORY that gem env prints, /usr/local/bin for the system Ruby here.
gem install says permission deniedThe system gem folder is /Library/Ruby/Gems/..., owned by root. A plain gem install with the system Ruby therefore fails with a permissions error. There are three ways out. Installing with sudo works but mixes root-owned files into the system; installing to your home folder is cleaner:
gem install <name> --user-install
That uses the USER INSTALLATION DIRECTORY from gem env. The best fix is to install a Ruby of your own with rbenv, RVM or Homebrew, where gems go into folders you own and no sudo is needed. Remember that a user-install executable lives in ~/.gem/ruby/<version>/bin, which must be on your PATH.
You do not need to browse folders to find one gem. These print paths and read nothing else:
gem contents <name>
gem which <name>
gem list <name>
gem contents lists every file a gem installed, and gem which prints the path of the file that require would load. They are the quickest way to open a gem's source in your editor when you want to read or debug it.
A project with a Gemfile usually installs into the shared gem folder above. If it sets a path, for example bundle config set --local path vendor/bundle, gems go inside the project instead. Check that one setting with bundle config get path. Be careful with the full bundle config listing and the global ~/.bundle/config file: they can hold credentials for private gem servers in plain text, so never paste them anywhere public. Bundler's documentation says a future Bundler 5 will default to a .bundle folder inside the project.
The system Ruby's gem folder was 122 MB on the Mac used here. See yours with du -sh "$(gem env gemdir)". To remove a gem the supported way:
gem uninstall <name>
gem cleanup
gem cleanup removes older versions of each gem, skipping any that another installed gem still needs. Preview it first with gem cleanup -n, which only reports what would go (newer RubyGems also accept --dry-run; the copy bundled with macOS knows only -n and --dryrun). For the system Ruby these commands need sudo, because the folder belongs to root. Do not delete folders under gems in Finder, because the matching specifications file stays behind and RubyGems still believes the gem exists.
Do not copy gem folders to a new Mac. Native extensions are compiled for one architecture and Ruby version. Instead, list your gems with gem list and reinstall them, or rely on each project's Gemfile.lock and run bundle install.
Spotlight and Finder searches leave out /Library/Ruby, and the user folders are hidden dot-folders. Gem files also sit many levels deep, so even a folder you open yourself shows a long list.
Everywhere finds files in hidden folders and system locations, so typing a gem and version, such as bundler-1, lists every copy of it across the system Ruby, rbenv and Homebrew, and typing .gemspec finds specification files. Press ⌘↵ to reveal one. It matches file names only, so gem list remains the place to check versions.
It depends on your Ruby. Run gem env and read INSTALLATION DIRECTORY. The system Ruby uses /Library/Ruby/Gems/<version>, and --user-install uses ~/.gem/ruby/<version>.
In the Ruby version's own folder under ~/.rbenv/versions. Each Ruby you install with rbenv keeps a separate set of gems.
The system Ruby's gem folder belongs to root. Use gem install <name> --user-install, or install your own Ruby with rbenv, RVM or Homebrew.
gem list shows them and gem uninstall <name> removes one. gem cleanup -n previews the removal of old versions without deleting anything.
Everywhere keeps track of every file on your Mac — including the folders Spotlight hides and drives you have unplugged. Free for a day, then $19 once.
Version 2.20.3 · macOS 13+ · 4.7 MB · notarised