Yashua Yashua - 1 year ago 118
Ruby Question

How to install gems without sudo on Mac OS X

I've read numerous posts but none so far has done the trick.

How can I, on OSX (El Capitan Beta) install a gem for my own user? Posts suggest specifying

for example but I cannot call
at all as it throws permission errors.

I followed "Install gem as user on OSX 10.10 Yosemite" but still cannot call

I installed Homebrew, installed rbenv per the above guide, installed a version of Ruby with rbenv, checked it was loaded correctly, but the final step in the guide is to call
gem install
which I still cannot do.

after installing
results in:

/Users/Me/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/stub_specification.rb:71:in `initialize':
Permission denied @ rb_sysopen - /Users/Ne/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/speci

rbenv env dump:


"brew and gem both throws 'Permission denied' error whenever I run it" seems related though it was not solved except by using some other method which I may have to do.

Answer Source

If you can't use gem without sudo, it sounds like you haven't initialized rbenv correctly because the shims aren't available.

These steps are from the documentation. Confirm you did them ALL:

Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.

$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

Ubuntu Desktop note: Modify your ~/.bashrc instead of ~/.bash_profile.

Zsh note: Modify your ~/.zshrc file instead of ~/.bash_profile.

Add rbenv init to your shell to enable shims and autocompletion.

$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

Same as in previous step, use ~/.bashrc on Ubuntu, or ~/.zshrc for Zsh.

Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up:

$ type rbenv
#=> "rbenv is a function"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download