How to manage newer Ruby installations in macOS without intervening with the default Ruby installations? 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' &gt;&gt; ~/.bash_profile #bash
brew install rbenv ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' &gt;&gt; ~/.bash_profile  # bash
echo 'eval "$(rbenv init -)"' &gt;&gt; ~/.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


rbenv not overriding default Ruby version
How to install ruby gems without sudo
Which version(s) of Mac OS X have Ruby installed by default?
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.