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

Published

If you’re reading this, you’ve probably been trying to install a Ruby gem on your Mac (such as Rails, Jekyll, or cocoapods), but you 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.

Here are some more reasons why you shouldn’t use the system Ruby.

If you tried to find a solution before reading this article, you might have come across people telling you to use sudo to install the gem. Unfortunately, even though you might see it a lot, it’s bad advice. Read my article to learn why you should never use sudo to install gems.

If you followed that advice, you probably ran into this other error:

ERROR: Failed to build gem native extension.

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

While there are various ways to install gems on a Mac, there’s really only one method that should be recommended: by installing a separate version of Ruby using a version manager.

I highly recommend using a Ruby manager because it allows you to have multiple versions of Ruby installed at the same time, and makes it easy to switch between them. This will save you a lot of headaches and confusion compared to other solutions.

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.

Read my definitive guide to learn how to install Ruby on Mac with chruby.