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

June 28, 2015

The Problem

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

Software development professional with expertise in application architecture, cloud solutions deployment, and financial products development. Possess a Master's degree in Computer Science and an MBA in Finance. Highly skilled in AWS (Certified Solutions Architect, Developer and SysOps Administrator), GCP (Professional Cloud Architect), Microsoft Azure, Kubernetes(CKA, CKAD, CKS, KCNA), and Scrum(PSM, PSPO) methodologies. Happy to connect