Installing Ruby on Rails with rbenv on macOS
Meta description (155 characters): Easily install Ruby on Rails, manage different Ruby versions, and start developing your Rails projects using Homebrew and rbenv on macOS.
🧠 What Will You Learn in This Guide?
This guide explains how to install Ruby on Rails using Homebrew and rbenv on macOS. The goal is to eliminate incompatibilities caused by the default old Ruby version and allow developers to easily manage different Ruby versions in different projects. At the end of the installation, you will have a fully equipped Rails development environment with Bundler and gem configurations.
⚙️ Prerequisites
Before you start, you must have:
- macOS 12.4 Monterey or newer
- Administrator access and active internet connection
- Homebrew package manager must be installed
- Node.js must be installed (JS runtime is required for Rails' Asset Pipeline feature)
1️⃣ Installing rbenv Version Manager
Install rbenv and ruby-build Plugin with Homebrew:
brew install rbenv
This command installs rbenv and ruby-build plugin. ruby-build makes it easy to install new Ruby versions.
Add rbenv to Autostart:
To have rbenv automatically loaded when the terminal is opened, add the following line to the .bash_profile file:
nano ~/.bash_profile
eval "$(rbenv init -)"
Save the file and exit (CTRL + O, ENTER, CTRL + X).
Enable Changes:
source ~/.bash_profile
Verify Installation:
type rbenv
If you see the output “rbenv is a function”, the installation is successful.
2️⃣ Installing Ruby Version
List Available Ruby Versions:
rbenv install -l
Install Ruby 3.1.2:
rbenv install 3.1.2
The compilation process may take a few minutes.
Set Default Ruby Version:
rbenv global 3.1.2
Check Installation:
ruby -v
Sample output:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
3️⃣ Gem and Bundler Configuration
Disable Documentation Generation:
echo "gem: --no-document" > ~/.gemrc
This reduces gem installation time.
Install Bundler:
gem install bundler
Bundler manages dependencies of Ruby projects.
Check Gem Installation Path:
gem env home
Sample output:
/Users/kullanici/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0
4️⃣ Installing Ruby on Rails
Install Rails:
gem install rails
Downloads and installs Rails and all necessary dependencies. Installation may take a few minutes.
Update rbenv Command Cache:
rbenv rehash
Required for recognition of new commands.
Verify Rails Installation:
rails -v
Output:
Rails 7.0.3.1
5️⃣ Managing rbenv and Ruby (Update & Uninstall)
Update on rbenv and ruby-build:
brew upgrade rbenv ruby-build
Installs the latest versions.
Uninstalling Old Ruby Version:
rbenv uninstall 2.1.3
Uninstalling rbenv:
brew uninstall rbenv
This removes rbenv and all Ruby versions from the system.
❓ Frequently Asked Questions (FAQ)
1. How does rbenv work?
It stores each Ruby version in separate directories and routes the active version through shims.
2. Why do you need Node.js?
Rails' Asset Pipeline feature requires Node.js to run JavaScript codes.
3. Why is the PATH variable edited?
To automatically promote rbenv executables when Terminal is opened.
4. How can I install a different version of Rails?
You can list the available versions with gem search '^rails$' --all and install the one you want with the gem install rails -v X.X.X command.
5. What should I do if the Rails command is not working?
After installing a new gem, be sure to run the rbenv rehash command.
🎯 Result
Now your macOS device has a complete environment for Ruby on Rails development 🎉 Thanks to rbenv, you can manage different Ruby versions and easily launch your Rails projects.
💡 You can try scalability and performance by deploying your new projects on the GenixNode platform!

