How to Fix Ruby Gems Permission Error on Mac OS X Yosemite

June 28, 2015

The Problem

2015 06 28

While trying to install a gem on Mac OS X Yosemite, I encountered the following error:

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

The Solution

Step 1: Install Rbenv

To start, you'll need to install Rbenv and Ruby-build:

brew install rbenv ruby-build

Next, add Rbenv to ~/.zshrc so it starts automatically:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc

Note: If you are not using Zsh, modify your ~/.bash_profile instead of ~/.zshrc.

Step 2: Restart Your Shell

Close your terminal and reopen it to apply the changes.

Step 3: Install Ruby, Set Global Version, and Rehash

Now, install Ruby and set it as your global Ruby version:

rbenv install 2.0.0-p247
rbenv global 2.0.0-p247
rbenv rehash

Step 4: Install Gems as Usual

You can now proceed to install gems without encountering permission issues.

gem install [gem-name]

Your gem should now install successfully!

Profile picture

Victor Leung, who blog about business, technology and personal development. Happy to connect on LinkedIn