How to resolve permission errors during gem install

When you try to install a Ruby gem using gem install, you may get a PermissionError error.

Example:

$ gem install docker-sync 
Fetching: thor-0.20.3.gem (100%) 
ERROR: While executing gem ... (Gem::FilePermissionError) 
 You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

This error occurs because you do not have permissions to write to the specified directory. In many cases, this problem is more likely to occur if you are using Ruby preinstalled on your system.

One way to avoid the error is to specify the directory to install to when doing a gem install. The following command can be used to install a gem in the /usr/local/bin directory

$ sudo gem install -n /usr/local/bin jekyll

By using this method, you can avoid permission errors and successfully install the gem.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top