Gem installs with Sudo (using Laptop and TB dotfiles)

After setting up a new machine with Thoughtbot Laptop, including using the Thoughtbot dotfiles, when attempting to install a gem, I get a permissions error, however sudo works of course. I’m switching from using an RVM-based workflow to the Rbenv one, so I’m a little new at this.

Here’s my output:

$ gem install bundler

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

Any ideas?

I believe this is due to the rbenv path. The error indicates that it is trying to write to the system ruby folder and not the rbenv path. You can dig through the TB Laptop script and check the steps for rbenv install and configure and run them manually to make sure you got rbenv setup correctly.

1 Like

This is really strange:

gem update --system works

but this happens:

[~] gem install bundler foreman pg rails thin --no-rdoc --no-ri
ERROR:  While executing gem ... (Errno::EACCES)
    Permission denied - /Users/briandear/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/.gitignore
[~] which gem                                                  
/Users/briandear/.rbenv/shims/gem

So it’s appearing to use the proper gem path, but it’s still violating my sanity with permission-denied.

I remember struggling with this myself and most of the problems were with my .zshrc file. I managed to isolate the issue by running each command from the Laptop script individually until I saw an error that I could work on fixing. It’s a tough question, since it depends on so many different things. Hope someone from TB can chime in to help you get this fixed.

This is probably fixed as of this commit. We had to force an rbenv rehash to make rbenv pick up its new binaries, including gem.