Run this command inside your terminal to install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
MacOS comes with Ruby pre-installed but we're going to use Homebrew to get the latest version.
To install Ruby with Homebrew, run:
brew install ruby
Now we need to add this installation to our path so that its used instead of the default MacOS one.
- Get the location of your Homebrew installed Ruby:
brew info ruby
- Get the location of your gems:
gem environment gemdir
- Use those to run the following command to prepend those locations to your path:
echo 'export PATH="{your-ruby-location}:{your-gem-location}:$PATH"' >> ~/.zshrc
Note Depending on your shell, you might need to replace
~/.zshrc
with~/.bashrc
or~/.bash_profile
, etc.
Mine looked like this:
echo 'export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc
Restart your terminal and run:
which ruby
to verify that it points to the Homebrew installed Ruby.
Run the following to install Ruby on Rails:
gem install rails
Restart your terminal and you should be good to go!