How to install a gem or update RubyGems if it fails with a permissions error

Gaurav picture Gaurav · Jan 30, 2013 · Viewed 486.4k times · Source

I'm trying to install a gem using gem install mygem or update RubyGems using gem update --system, and it fails with this error:

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

Does anyone have an idea how to solve this?

Answer

nathanwhy picture nathanwhy · Jul 8, 2016

Try adding --user-install instead of using sudo:

gem install mygem --user-install