Skip to content

You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory #938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
GuoZhiQiang opened this issue Oct 11, 2016 · 29 comments
Closed

Comments

@GuoZhiQiang
Copy link

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 ?

@jeremy
Copy link
Member

jeremy commented Oct 11, 2016

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

@jeremy jeremy closed this as completed Oct 11, 2016
@mislav
Copy link
Member

mislav commented Oct 11, 2016

@GuoZhiQiang Also, see rbenv-doctor for a script that can detect installation issues for you: https://github.com/rbenv/rbenv-installer#rbenv-doctor

@GuoZhiQiang
Copy link
Author

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

@jeremy
Copy link
Member

jeremy commented Oct 12, 2016

@GuoZhiQiang did you try rbenv doctor as @mislav suggests?

When you run rbenv init, what does it report?

@GuoZhiQiang
Copy link
Author

it reports that

# Load rbenv automatically by appending
# the following to ~/.bash_profile:

eval "$(rbenv init -)"

@GuoZhiQiang
Copy link
Author

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

@jeremy
Copy link
Member

jeremy commented Oct 12, 2016

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!

@GuoZhiQiang
Copy link
Author

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

@mislav
Copy link
Member

mislav commented Oct 12, 2016

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!

@GuoZhiQiang
Copy link
Author

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

@mislav
Copy link
Member

mislav commented Oct 13, 2016

@GuoZhiQiang You still didn't install rbenv properly. Run the rbenv-doctor again to check if rbenv shims directory is in your PATH.

@DavidLJ
Copy link

DavidLJ commented Oct 13, 2016

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.

@GuoZhiQiang
Copy link
Author

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

@mislav
Copy link
Member

mislav commented Oct 17, 2016

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

@GuoZhiQiang
Copy link
Author

GuoZhiQiang commented Oct 18, 2016

@mislav @jeremy I have changed the Ruby from system to rbenv's versions. The gem install bundler run successfully. Thanks !

@marcus-cr
Copy link

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!

@hfossli
Copy link

hfossli commented Mar 9, 2017

First determine your goal. Is it

"I'm not sure I installed rbenv and a ruby version correctly"
Yep, sure it can be tricky.

  1. sudo xcode-select --install
  2. Install rbenv with brew install rbenv
  3. Add eval "$(rbenv init -)" to the end of ~/.zshrc or ~/.bash_profile
  4. Install a ruby version rbenv install 2.3.0
  5. Select a ruby version by rbenv rbenv global 2.3.0
  6. Open a new terminal window
  7. Verify that the right gem folder is being used with gem env home (should report something in your user folder not system wide)

"I want to use bundler and rbenv together"
Perfect match!

  1. Make sure you installed rbenv correctly ☝️
  2. Select a ruby version locally for the folder you are located in e.g. rbenv local 2.3.0 (this creates a file called .ruby-version in the directory)
  3. Verify that the right gem folder is being used with gem env home (should report something in your user folder not system wide)
  4. Run gem install bundler
  5. Run bundle install
  6. Run on of your favorite gems defined in the Gemfile 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.

  1. Make sure you installed rbenv correctly ☝️
  2. Select a ruby version globally by e.g. rbenv global 2.3.0 or even better locally for the folder you are located in e.g. rbenv local 2.3.0
  3. Run 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 with sudo gem install ...

Sorry, something went wrong.

@manoharv
Copy link

resolved the issue by trying with sudo that is
"sudo gem install mysql2"

101sam pushed a commit to 101sam/osx-dev-setup that referenced this issue Oct 6, 2017
@resteorts
Copy link

Thank you! This was super helpful:)

@tfalbo
Copy link

tfalbo commented Dec 10, 2017

Setting rbenv version as global worked for me! Thanks @hfossli !

@midorichan
Copy link

Thanks everyone. Had this issue today and got to solve it following the instructions give here 👍

@yanlee26
Copy link

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?

@JittenderKumar
Copy link

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.

@tcodes0
Copy link

tcodes0 commented Feb 19, 2018

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:

  • Running which ruby or which gem will show what version it is running (your's or the system's)
  • Running which -a ruby or which -a gem will show all versions your system currently possesses.
  • Ensuring /usr/local/bin comes before /usr/bin on your $PATH
    • To edit the PATH variable: find it on a bash init file, likely $HOME/.bashrc, and change its value.
    • To see what it is currently set to: echo $PATH
  • Restarting the terminal after trying other steps could also help
    • You can also run source $HOME/.bashrc
  • Running /usr/local/bin/ruby or /usr/local/bin/gem directly

@channabasavagola-zz
Copy link

Super helpful!

@ijeism
Copy link

ijeism commented Apr 25, 2018

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)

@abeward
Copy link

abeward commented Oct 9, 2018

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.

@Yuexi-Li
Copy link

Yuexi-Li commented Nov 7, 2018

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.

@mislav
Copy link
Member

mislav commented Nov 8, 2018

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.

@rbenv rbenv locked as resolved and limited conversation to collaborators Nov 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests