Install Ruby with Chruby
If you are a casual user and won't be using Ruby frequently, you can use Homebrew to install Ruby. See the section, Install Ruby with Homebrew. Most developers should install a software version manager before installing Ruby. It will help you manage multiple versions of Ruby. I recommend asdf. Asdf can manage versions of many languages, including Ruby and Node. Instructions for asdf are in the section, Install Asdf Version Manager.
If you don't want to use asdf, or if you have problems with it, I recommend Frum or Chruby. Frum is the newest and fastest Ruby version manager. Chruby is also good. Rbenv and rvm are also popular as Ruby version managers. Sam Stephenson's rbenv is more complex than Chruby (it installs extra “shim” files). RVM was once the most popular of Ruby version managers but its additional features (its gemsets) are no longer needed and it adds unnecessary complexity.
Before you get started
You'll need a terminal application to install Ruby. Apple includes the Mac terminal but I prefer Warp Terminal. Warp is an easy-to-use terminal application, with AI assistance to help you learn and remember terminal commands. Download Warp Terminal now; it's FREE and worth a try.
Mac system Ruby
MacOS comes with a "system Ruby" pre-installed. MacOS Sonoma includes Ruby 2.6.10 which is not the newest version. It's a bad idea to use the Mac system Ruby. See the article Do not use the MacOS system Ruby. You can see the system Ruby with which ruby
and ruby -v
.
Leave the system Ruby in place and install the Chruby version manager and the newest Ruby version.
Ruby-install and Chruby
Use Homebrew to install the ruby-install utility and the chruby Ruby version manager.
$ brew install ruby-install chruby
You'll see beer mug emojis as Homebrew installs the utilities.
Verify that ruby-install is available:
$ ruby-install -V
ruby-install: 0.7.1
We must add Chruby to the system environment before we can use it to manage Ruby versions.
Add Chruby to the .zshrc file
Edit the ~/.zshrc
file in your text editor. If you haven’t installed a text editor, use the macOS TextEdit application. Here’s a shortcut to open the file in TextEdit from the Terminal:
$ open -e ~/.zshrc
Add configuration commands for Chruby:
### ~/.zshrc~
# enable chruby
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
chruby ruby-3.4.1
The first two lines (with the hash characters) are comments. The third line makes the chruby program available in the shell. The fourth line will automatically switch the current version of Ruby when you change directories if a hidden file indicates a specific Ruby version. The final line makes Ruby version 3.4.1 the default Ruby in the Terminal.
Save the file.
🚩 Close and reopen the Terminal window for the changes to the ~/.zshrc
file to be recognized.
After closing and reopening the Terminal window, use chruby -h
to check that Chruby was installed successfully.
Next we'll install Ruby.
Install Ruby
If you've installed Chruby and the ruby-install utility, install the newest version of Ruby using ruby-install for use with the Ruby version manager.
Use the ruby-install utility to check for the newest Ruby version.
$ ruby-install --latest
Or check online for the current recommended version of Ruby.
When this was written, Ruby 3.4 was the newest version (3.4.1 was released on Dec 25, 2024).
Use ruby-install to install the newest Ruby version.
$ ruby-install --latest ruby
You’ll see diagnostic messages and progress updates. Installation may take thirty minutes or more.
🚩 After installation, close and re-open the terminal window.
Verify that the newest version of Ruby is installed with ruby -v
.
When this was written, Ruby 3.4.1 was the newest version (released on Dec 25, 2024).
If you see Ruby version 2.6.10, it is the system Ruby and you likely forgot to close and re-open the terminal window.
The Tips: Uninstalling Ruby section explains where Ruby versions are installed and how to remove them.
Next, you can optimize the Ruby development environment by updating gems. See the Update Gems section.