rbenv: 'gem env home' does not return '~/.rbenv/versions//lib/ruby/gems/...'

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 16 (2 by maintainers)

Most upvoted comments

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

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.

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 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

adding only this to your .zshrc or .bashrc did the trick for me

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

source ~/.zshrc

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

Here are the list of steps I followed:

  • installedrbenv on my MacOS Monterey: brew install rbenv ruby-build
  • rbenv install 3.1.2
  • rbenv global 3.1.2
  • the problem is that running gem env home was still showing the default System Ruby config and which -a ruby was printing only /usr/bin/ruby

The solution that worked for me was the one proposed by @Chasty.

After editing .zshrc and executing source ~/.zshrc, finally launching which -a ruby is printing both installed versions:

/Users/myusername/.rbenv/shims/ruby
/usr/bin/ruby

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.

rebenv rehash solves the problem

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

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

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

Thank you so much !

@canrosss 100%!!! thanks