You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory

Published by Moncef Belyamani - Updated

Did you just try to install a Ruby gem (such as Rails, Jekyll, or cocoapods) on your Mac and got this write permissions error?

ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory

This is one of the most common errors people face. You’ll get this error for any gem you try to install on a Mac that hasn’t yet been properly configured for Ruby development.

Apple preinstalls Ruby on all Macs, and the default location where gems would get installed is in the /Library/Ruby/Gems/2.6.0 directory. However, that directory is not meant to be modified, which is why Apple doesn’t give you permissions to write to it.

TL;DR If you just want to get your Ruby project working as quickly as possible, here’s a summary of this article:

  • Managing Ruby on Macs can be painful. Even a working installation can stop working for mysterious reasons, seemingly all by itself.
  • Fixing a broken installation is tedious and error-prone.
  • If you have a clean Mac, try my free step-by-step guide for installing Ruby on a Mac, which only covers the minimum tools required (Homebrew, chruby, ruby-install).
  • If you want to be up and running in 15 minutes or less, even if you have a broken development setup, my Ruby on Mac script is guaranteed to work, or your money back. Read what people say about Ruby on Mac, and here are more Twitter testimonials.

Why you shouldn’t use the system Ruby on Mac

The system Ruby is old

Monterey (macOS 12) ships with Ruby 2.6.8. This version reached end of life at the end of March 2022. This means there won’t be any more updates and security fixes to the 2.6.x series. The latest version of Ruby is currently 3.1.2.

The system Ruby can’t be updated

Apple includes Ruby on macOS for compatibility with legacy software. It’s not meant for consumer use. And when a new version of Ruby comes out, Apple doesn’t update Ruby within the same macOS version.

Apple will probably stop preinstalling Ruby on macOS

In the release notes for macOS Catalina, Apple mentioned it won’t include Ruby in future versions of macOS:

Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app.

Since then, there have been two macOS versions (Big Sur and Monterey), so it’s not clear when that change will happen, but I like to stay ahead of the curve, which is why Ruby on Mac will still work when that happens.

So what’s the proper way to install gems on a Mac?

Glad you asked! The most reliable method, and the only one I recommend, is to install a separate and newer version of Ruby using a version manager. If you’re really interested in all the possible options, including ones I don’t recommend, read my definitive guide to installing gems on a Mac.

I highly recommend using a Ruby version manager because it allows you to have multiple versions of Ruby installed at the same time, and makes it easy to switch between them. Even if you’re using Ruby for the first time, it’s worth your time to learn how to use a Ruby manager because you will inevitably need one.

Over the past ten years, I’ve helped thousands of people set up Ruby on their Mac. From clean Macs to the most obscure issues, I’ve seen and fixed it all. And the most reliable solution is to use a version manager, specifically chruby.

Install Ruby with a version manager

At a high level, there are a minimum of five steps to a working Ruby environment on macOS with a Ruby manager:

  1. Install Homebrew (which will also install the prerequisite Apple command line tools)
  2. Install a Ruby version manager such as chruby and ruby-install (others include rbenv, asdf, and RVM)
  3. Configure the Ruby version manager
  4. Install a specific version of Ruby
  5. Switch to that version of Ruby

You have two options for performing those steps:

  • Have everything set up for you in minutes with a single command
  • Spend an hour or more setting everything up manually

Have everything set up for you in minutes with a single command

Ruby on Mac will automatically install Ruby with chruby, ruby-install, and all the other development tools you’ll need for Rails or Jekyll. It will save you so much time and frustration.

It doesn’t just have a one-time use. You can run it over and over by simply typing “rom” to keep your system up to date and secure. And the next time you get a new Mac, the Ultimate version will save you an entire day because it can also automatically install all your Mac apps, fonts, macOS preferences, and GitHub repos, in addition to a complete development environment. You get all of these time savings now and in the future for a one-time cost.

When you buy Ruby on Mac today, you’ll be supporting an independent developer, and if you need it for your job or business, you should be able to expense it.

Read what people say about Ruby on Mac.

Spend an hour or more setting everything up manually

If you haven’t yet tried to install Ruby or other development tools on your Mac, you should be able to get up and running with the basics by following my free step-by-step guide for installing Ruby on a Mac.

This is the manual equivalent of the “Basic” version of Ruby on Mac, minus the comprehensive troubleshooting guide. You’ll then need to manually install gems, and any other necessary dev tools.