rbenv: You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory
I have installed Hombrew .And have rbenv installed by brew install rbenv
. But when i run gem install bundler
,it said : You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory
. I want to install Bundler to manage gems, but it failed. Maybe something wrong with me ,can you help me ?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 29 (8 by maintainers)
Commits related to this issue
- Update .bash_prompt https://github.com/rbenv/rbenv/issues/938 — committed to 101sam/osx-dev-setup by limitlessv 7 years ago
First determine your goal. Is it
“I’m not sure I installed
rbenv
and a ruby version correctly” Yep, sure it can be tricky.brew install rbenv
eval "$(rbenv init -)"
to the end of~/.zshrc
or~/.bash_profile
rbenv install 2.3.0
rbenv global 2.3.0
gem env home
(should report something in your user folder not system wide)“I want to use
bundler
andrbenv
together” Perfect match!rbenv local 2.3.0
(this creates a file called.ruby-version
in the directory)gem env home
(should report something in your user folder not system wide)gem install bundler
bundle install
Gemfile
bybundle exec ...
e.g.bundle exec fastlane
“I want to install a gem on user for a specific version of ruby” Nice, rbenv is your friend.
rbenv global 2.3.0
or even better locally for the folder you are located in e.g.rbenv local 2.3.0
gem install ...
“I want to install a gem globally on my system ruby” Then why are you using
rbenv
? Okay, if you decide this is the right option for you then go ahead withsudo gem install ...
resolved the issue by trying with sudo that is “sudo gem install mysql2”
Edit your
~/.bash_profile
and puteval "$(rbenv init -)"
at the end 😊Just to add to what @jeremy and @mislav said:
After appending your ~/.bash_profile with
export RBENV_ROOT=/usr/local/var/rbenv
(Homebrew’s caveat), and then appendingeval "$(rbenv init -)"
to the bottom, be sure to$ exit
your terminal and login again.I had this same issue with permissions and couldn’t even wget rbenv-doctor until I appended ~/.bash_profile and hopped out and back in Terminal
Thanks!
@DavidLJ I’m not sure why.
@GuoZhiQiang OK that’s a good start. Now, type
rbenv version
and make sure that it’s not “system”. Then, dogem install bundler
and it should work!So for me, after MANY hours of trying to figure this out, switching to the new rbenv version (i.e. changing from system to the new version) did the trick.
A similar situation On MacOS using bash as shell, the permission issue can happen because of BSD Ruby that ships with MacOS. If you install another Ruby (a newer one), using homebrew, for example, then you end up with two Rubies, but the BSD Ruby is owned by root and you can’t write to it.
Do NOT think a
sudo
will help.You need to make sure when you call
ruby
orgem
from the terminal, you’re getting the new Ruby, likely/usr/local/bin/ruby
, and not the default/usr/bin/ruby
.You can try:
which ruby
orwhich gem
will show what version it is running (your’s or the system’s)which -a ruby
orwhich -a gem
will show all versions your system currently possesses./usr/local/bin
comes before/usr/bin
on your $PATH$HOME/.bashrc
, and change its value.echo $PATH
source $HOME/.bashrc
/usr/local/bin/ruby
or/usr/local/bin/gem
directly@mislav @jeremy I have changed the Ruby from system to rbenv’s versions. The
gem install bundler
run successfully. Thanks !Go ahead and put
eval "$(rbenv init -)"
at the end of your.bash_profile
. If that file doesn’t exist in your home directory, create it. Then open a new shell and try the doctor again. Should be working!Unfortunately, none of these solutions worked for me.
What ultimately worked?
[REDACTED BY @mislav]
I don’t know that it’s the *right way to do it, but it unblocked me, so I’m happy with it for now.
Thanks everyone. Had this issue today and got to solve it following the instructions give here 👍
Setting rbenv version as global worked for me! Thanks @hfossli !
Can you run
sudo xcode-select --install
and try again? If it doesn’t work, please report the issue in the ruby-build repo. Thanks!