5

macOS comes with some default ruby installations, more here, that I do not want to overwrite by running gems commands as sudo. I tried rbenv, instructed here, but I am getting a permission error in the last command gem update --system such that

brew update
brew install ruby
echo 'export PATH=/usr/local/Cellar/ruby/2.4.1_1/bin:$PATH' >> ~/.bash_profile #bash
brew install rbenv ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile  # bash
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile               # bash
rbenv install 2.4.1
rbenv local 2.4.1
rbenv global 2.4.1
rbenv rehash
gem update --system
Updating rubygems-update 
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory. 

I do not want to intervene with the default ruby installation in macOS, not to get the need for a fresh installation of the whole OS.

What is a proper way to install newer version of Ruby on macOS without intervening with the default ruby?

Further questions on Ruby in macOS

  1. rbenv not overriding default Ruby version

  2. How to install ruby gems without sudo

  3. Which version(s) of Mac OS X have Ruby installed by default?

  • The command you mentioned isn't included in the answer you refer to. Can you add the whole sequence of commands you've used? – nohillside Jun 27 '17 at 14:58
  • 1
    Try to run the commands from rbenv onwards in a newly started shell so that the PATH gets set correctly. – nohillside Jun 27 '17 at 15:41
  • @patrix I got the command run, by testing the last command in a new shell, but unable to install packages with gem, shown here, this may be a small pkg-related problem or bigger problem, dunno yet. – hhh Jun 27 '17 at 16:06
3

Looks like you only update PATH etc in the shell profiles, but not in the running shell. Try to run the commands from rbenv onwards in a newly spawned shell.

  • Thank you for the answer, moved the question about LoadError here. – hhh Jun 27 '17 at 22:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .