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
rbenvand a ruby version correctly” Yep, sure it can be tricky.brew install rbenveval "$(rbenv init -)"to the end of~/.zshrcor~/.bash_profilerbenv install 2.3.0rbenv global 2.3.0gem env home(should report something in your user folder not system wide)“I want to use
bundlerandrbenvtogether” Perfect match!rbenv local 2.3.0(this creates a file called.ruby-versionin the directory)gem env home(should report something in your user folder not system wide)gem install bundlerbundle installGemfilebybundle 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.0or even better locally for the folder you are located in e.g.rbenv local 2.3.0gem 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_profileand 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$ exityour 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 versionand make sure that it’s not “system”. Then, dogem install bundlerand 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
sudowill help.You need to make sure when you call
rubyorgemfrom the terminal, you’re getting the new Ruby, likely/usr/local/bin/ruby, and not the default/usr/bin/ruby.You can try:
which rubyorwhich gemwill show what version it is running (your’s or the system’s)which -a rubyorwhich -a gemwill show all versions your system currently possesses./usr/local/bincomes before/usr/binon your $PATH$HOME/.bashrc, and change its value.echo $PATHsource $HOME/.bashrc/usr/local/bin/rubyor/usr/local/bin/gemdirectly@mislav @jeremy I have changed the Ruby from system to rbenv’s versions. The
gem install bundlerrun 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 --installand try again? If it doesn’t work, please report the issue in the ruby-build repo. Thanks!