You Don’t Have Write Permissions for the /library/ruby/gems/2.6.0 Directory Error Fix

The error message: “you don’t have write permissions for the /Library/Ruby/Gems/2.6.0 directory” usually appears on macOS when trying to install a Ruby gem globally using the system Ruby, which is protected by macOS for security reasons.

🔧 How to Fix It

You have several options depending on what you’re comfortable with. Here are the safest and most common solutions:


✅ Option 1: Use sudo (Not recommended for general use)

You can prepend sudo to your command to gain temporary admin rights:

sudo gem install <gem_name>

However, this is not recommended long-term because:

  • It modifies system files

  • It can break macOS updates or system tools


✅ Option 2: Use a Ruby version manager (Recommended)

Using a version manager like rbenv or RVM allows you to manage and install gems without touching the system Ruby.

📦 Install rbenv (with Homebrew):

brew install rbenv ruby-build
rbenv install 3.2.2 # or your desired version
rbenv global 3.2.2

Then install your gem:

gem install <gem_name>

This installs everything in your user space, avoiding permission issues.

you don't have write permissions


✅ Option 3: Install gems to user space with --user-install

If you only want a quick fix:

gem install <gem_name> --user-install

Your gems will be installed to:

~/.gem/ruby/2.6.0/

To use these gems from the command line, add this to your ~/.zshrc or ~/.bash_profile:

export PATH="$HOME/.gem/ruby/2.6.0/bin:$PATH"

Then restart your terminal or run source ~/.zshrc.


🛡️ Final Note:

Modifying system Ruby can lead to unintended consequences on macOS. Using a version manager is the safest and most flexible long-term solution.