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)
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
?You do not to need to install gemset like @canrosss said, however, running
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 withrbenv 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 withrbenv 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
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 commandrvm 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 mesource ~/.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:
rbenv
on my MacOS Monterey:brew install rbenv ruby-build
rbenv install 3.1.2
rbenv global 3.1.2
gem env home
was still showing the default System Ruby config andwhich -a ruby
was printing only/usr/bin/ruby
The solution that worked for me was the one proposed by @Chasty.
After editing
.zshrc
and executingsource ~/.zshrc
, finally launchingwhich -a ruby
is printing both installed versions:Had a similar issue. Followed above instructions but the
gem env home
was always incorrect. Restarting the terminal after therbenv 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