Use a Ruby version management tool. This class of tool allows you to install and switch between multiple versions of Ruby without needing administrator permissions and without overwriting the operating system installed version:
- rbenv
- Ruby Version Manager (RVM)
- Unleash Ruby (URU)
- chruby
Example: rbenv
Install rbenv using either of the commands below…
# with curl
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
# alternatively, with wget
wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash
…then install the latest Ruby:
rbenv install 2.7.0-preview3
Answer from Graham Miln on Stack ExchangeUse a Ruby version management tool. This class of tool allows you to install and switch between multiple versions of Ruby without needing administrator permissions and without overwriting the operating system installed version:
- rbenv
- Ruby Version Manager (RVM)
- Unleash Ruby (URU)
- chruby
Example: rbenv
Install rbenv using either of the commands below…
# with curl
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
# alternatively, with wget
wget -q https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer -O- | bash
…then install the latest Ruby:
rbenv install 2.7.0-preview3
@nohillside has reminded me in his comment:
The recommended way is "switch to your admin account, install ruby, switch back".
How to install ruby on Mac using rbenv? - Stack Overflow
macos - How do I install Ruby without using RVM on OS X? - Stack Overflow
trouble installing on macos
Problems installing ruby and rails on Mac with apple silicon
Videos
In case Macports does not work for you, try Homebrew:
rvm autolibs homebrew
Please note: Although it is not required, you might want to install Homebrew before using it with autolibs. It keeps Homebrew out of RVM directories.
Using Homebrew, you can either install and manage a single version of Ruby:
brew update
brew install ruby
Or, even better, use rbenv as a flexible alternative to RVM:
brew update
brew install rbenv
brew install ruby-build
rbenv install 2.0.0-p247
rbenv rehash
rbenv then makes it easy to use a specific version of Ruby either globally or per project (which can then be added to source control).
Note that you may want to follow the advice from rbenv's "caveats" (brew info rbenv), particularly the part about adding eval "$(rbenv init -)" to your profile.
I had trouble with installing ruby and rails on my Mac with M2 and it took me hours to figure out what is wrong. If anybody is having problems try to do it like this:
install homebrew
brew install rbenv ruby-build
rbenv init
add 'eval "$(rbenv init -)"' to
~/.zshrcsource ~/.zshrc or reopen the terminal
rbenv install 3.3.5
rbenv global 3.3.5
reopen the terminal and check it with ruby -v
gem install rails
check rails -v
Hope that this helps.