Rbenv: 'gem env home' does not return '~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...'

Created on 6 Mar 2016  Â·  14Comments  Â·  Source: rbenv/rbenv

I am trying to install gems locally and without sudo but receive the error, 'You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.' This is the system ruby gems directory in which I do not want to install gems. Using 'gem install blah', gems should be installed to ~/.rbenv/versions/<ruby-version>/lib/ruby/gems/...

I have pasted more info to a gist, found here. https://gist.github.com/nielssorensen/8ee52a70750d69580351

Most helpful comment

You can do the following:

First reinstall for example am using 2.4.0 so i did this

rbenv uninstall 2.4.0;rbenv install 2.4.0

Next in my .zshrc i have this lines in for path make sure to check what are you lines the goal its have whatever you have in you PATH plus the path to .rbenv/bin and the plugin path

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

Make sure to have this at the end of ur file .zshrc or .bashrc

Next make sure you have this
https://github.com/jf/rbenv-gemset
git clone git://github.com/jf/rbenv-gemset.git $HOME/.rbenv/plugins/rbenv-gemset
And check with
gem env home now should point to ur local ruby installation in your home

╭─hagbard@amd-fx ~ ‹2.4.0›
╰─$ gem env home
/home/hagbard/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0

gem install bundle

All 14 comments

Hello, it seems that even though you've installed several Ruby versions managed by rbenv, you're still using the global system version that requires use of sudo to install gems. You can check that with rbenv version.

Ideally, you should switch to one of rbenv-managed Ruby versions to set as your new "global" version to install all gems to without sudo. You can do this with rbenv global 2.3.0 (choose whichever version you want to be your default). Then, gem install ... should just work.

I've had the same problem but setting the rbenv global to the version of ruby I am using did not work.

Could anybody help me out?

@mufernando Check out the rbenv-doctor script to help you debug what you did wrong while setting up rbenv.

You can do the following:

First reinstall for example am using 2.4.0 so i did this

rbenv uninstall 2.4.0;rbenv install 2.4.0

Next in my .zshrc i have this lines in for path make sure to check what are you lines the goal its have whatever you have in you PATH plus the path to .rbenv/bin and the plugin path

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"

Make sure to have this at the end of ur file .zshrc or .bashrc

Next make sure you have this
https://github.com/jf/rbenv-gemset
git clone git://github.com/jf/rbenv-gemset.git $HOME/.rbenv/plugins/rbenv-gemset
And check with
gem env home now should point to ur local ruby installation in your home

╭─hagbard@amd-fx ~ ‹2.4.0›
╰─$ gem env home
/home/hagbard/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0

gem install bundle

@canrosss 100%!!!! thanks

Thank you so much !

@canrosss you save my day. Typo: unstall => uninstall

@canrosss Thanks a lot. That works for me as well.

Did you remember to rbenv rehash?

# Other major instructuions
$ rbenv install -v 2.5.0
# Compiler stuff and about a while later.
# BTW, @rbenv, don't forget to tell everybody about the -v option for install. Looking at a command doing nothing is no fun.
$ rbenv global 2.5.0
$ rbenv rehash
# Things should work now. Verify that they are
$ rbenv which gem
# You should see something like /home/Jason/.rbenv/versions/2.5.0/bin/gem
$ gem env home
# You should see something like /home/Jason/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
$ gem install bundler
# And then rehash again for good practice.
$ rbenv rehash

You do not to need to install gemset like @canrosss said, however, running

for settings in ~/.bashrc ~/.zshrc; do
  if [[ -f "$settings"]]; then
   echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> $settings
   echo 'eval "$(rbenv init -)"' >> $settings
   echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> $settings
 fi
done

does make sense and should be done after you git rbenv and ruby-build.

@canrosss perfect! thank you!

I had the same problem on Mac OS, fixed it by setting rbenv global <ruby_version>

rebenv rehash solves the problem

Had a similar issue. Followed above instructions but the gem env home was always incorrect. Restarting the terminal after the rbenv global 2.7.0 seemed to fix the issue for me.

I followed @canrosss solution with some modifications.

This was added at the end of my .zshrc or .bashrc file

eval "$(rbenv init -)"
export PATH="$HOME/.rbenv/bin:$PATH"

I installed this https://github.com/jf/rbenv-gemset using this command on home directory
git clone git://github.com/jf/rbenv-gemset.git $HOME/.rbenv/plugins/rbenv-gemset

I already had rvm installed in my system. So gem env home command was giving path of rvm.
I removed rvm using command rvm implode

then ran gem env home command and it gave rbenv gemset version.

Note: After updating .zshrc you need to run the command in terminal
source ~/.zshrc

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sandys picture sandys  Â·  4Comments

sonnybrakes picture sonnybrakes  Â·  4Comments

HuckyDucky picture HuckyDucky  Â·  4Comments

dazza-codes picture dazza-codes  Â·  4Comments

wakproductions picture wakproductions  Â·  4Comments