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 ?
$ brew info rbenv | tail -7
==> Caveats
Rbenv stores data under ~/.rbenv by default. If you absolutely need to
store everything under Homebrew's prefix, include this in your profile:
export RBENV_ROOT=/usr/local/var/rbenv
To enable shims and autocompletion, run this and follow the instructions:
rbenv init
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
Edit your ~/.bash_profile and put eval "$(rbenv init -)" at the end 😊
@GuoZhiQiang Also, see rbenv-doctor for a script that can detect installation issues for you: https://github.com/rbenv/rbenv-installer#rbenv-doctor
@jeremy I'm sorry to disturb you ,but where is the .bash_profile ? I cant found it in my root directory. Also not have the directory ~/.rbenv or /usr/local/var ? Please help me again . Thanks very much.
@GuoZhiQiang did you try rbenv doctor as @mislav suggests?
When you run rbenv init, what does it report?
it reports that
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
when i run the doctor @mislav have suggested , it reports that
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: not found
The directory `/Users/guo/.rbenv/shims' must be present in PATH for rbenv to work.
Please run `rbenv init' and follow the instructions.
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20160602)
Counting installed Ruby versions: none
There aren't any Ruby versions installed under `/Users/guo/.rbenv/versions'.
You can install Ruby versions like so: rbenv install 2.2.4
Checking RubyGems settings: OK
Auditing installed plugins: OK
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!
Great , thanks ! I'm trying to install Ruby, so i run the command :rbenv install 2.2.4(I have tried from 2.0.0 to 2.3.0).It reports that
BUILD FAILED (OS X 10.11.6 using ruby-build 20160602)
Inspect or clean up the working tree at /var/folders/l5/f58yyfz17yl_7lp_4ntbzzwh0000gn/T/ruby-build.20161012173755.4968
Results logged to /var/folders/l5/f58yyfz17yl_7lp_4ntbzzwh0000gn/T/ruby-build.20161012173755.4968.log
Last 10 log lines:
Referenced from: /private/var/folders/l5/f58yyfz17yl_7lp_4ntbzzwh0000gn/T/ruby-build.20161012173755.4968/ruby-2.2.4/./miniruby (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
dyld: Symbol not found: _clock_gettime
Referenced from: /private/var/folders/l5/f58yyfz17yl_7lp_4ntbzzwh0000gn/T/ruby-build.20161012173755.4968/ruby-2.2.4/./miniruby (which was built for Mac OS X 10.12)
Expected in: /usr/lib/libSystem.B.dylib
make: *** [.rbconfig.time] Trace/BPT trap: 5
make: *** Waiting for unfinished jobs....
make: *** [encdb.h] Trace/BPT trap: 5
The Ruby install failed. What can i do next? @jeremy
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!
Thanks @mislav ! I have the Ruby installed successfully. Then i run the command :gem install bundler again. It still reports :
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
Then what can i do? @mislav @jeremy
@GuoZhiQiang You still didn't install rbenv properly. Run the rbenv-doctor again to check if rbenv shims directory is in your PATH.
Apologies to you both: I just logged on following a suggestion in an EdX Python course, and I find this conversation listed in my notifications.
Do you know why? Or where should I look to larn meself th basic larnin'?
Thanks.
I have runned the doctor again. It says the PATH is OK:
Checking for `rbenv' in PATH: /usr/local/bin/rbenv
Checking for rbenv shims in PATH: OK
Checking `rbenv install' support: /usr/local/bin/rbenv-install (ruby-build 20160602)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
Is it right? @mislav
@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, do gem install bundler and it should work!
@mislav @jeremy I have changed the Ruby from system to rbenv's versions. The gem install bundler run successfully. Thanks !
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 appending eval "$(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!
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 rbenveval "$(rbenv init -)" to the end of ~/.zshrc or ~/.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 bundler and rbenv 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 bundlerbundle installGemfile by bundle 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.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 with sudo gem install ...
resolved the issue by trying with sudo that is
"sudo gem install mysql2"
Thank you! This was super helpful:)
Setting rbenv version as global worked for me! Thanks @hfossli !
Thanks everyone. Had this issue today and got to solve it following the instructions give here 👍
yanlideMacBook-Pro:hijiangtao.github.io yanli$ brew info rbenv | tail -7
==> Dependencies
Recommended: ruby-build
==> Options
--without-ruby-build
Build without ruby-build support
--HEAD
Install HEAD version
And How to fix?
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
Getting this error while installing cocoapods. Even not a single command is executing.
Provide solution.
Thanks in advance.
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 or gem 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 or which gem will show what version it is running (your's or the system's)which -a ruby or which -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 $PATHsource $HOME/.bashrc/usr/local/bin/ruby or /usr/local/bin/gem directlySuper helpful!
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.
$ rbenv versions
* system (set by /Users/apple/.rbenv/version)
2.2.4
$ rbenv local 2.2.4
$ rbenv versions
system
* 2.2.4 (set by /Users/apple/.ruby-version)
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.
Same situation. Your code works. Thank you!
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.
Please don't use sudo chown or any other sudo command to "fix" rbenv problems!
Instead, ensure that rbenv is installed correctly and that you've selected a version other than system to be either a global or local rbenv version. Use rbenv version and gem env to see where things will be installed; if you see /Library/Ruby/Gems/..., something is wrong.
Most helpful comment
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 ...