While macOS comes with a system Ruby pre-installed, it’s generally not recommended to use that version for Rails development. Instead, most Ruby developers on macOS opt for a Ruby version manager. Here’s why and what you should consider:
Why Not Use the System Ruby?
Limited Flexibility: The system Ruby is maintained by Apple and is usually out-of-date for modern Rails requirements.
Potential Conflicts: Modifying the system Ruby can lead to conflicts with macOS utilities and make OS upgrades more complicated.
Gem Installation Issues: Installing gems that require native extensions might require elevated permissions if using the system install.
Recommended Approach: Use a Ruby Version Manager
Using a version manager allows you to install and switch between different Ruby versions on a per-project basis. This is extremely useful if:
You want to test your Rails app against different Ruby versions.
You manage multiple projects that require different Ruby versions.
You need more control over gem environments.
The two most popular Ruby version managers in the community are:
1. rbenv
Pros:
Lightweight and simple to use.
Integrates well with Homebrew (which is popular on macOS).
Installation Example:
Install via Homebrew:
bash
brew install rbenv
Initialize rbenv (typically added to your shell configuration file):
bash
rbenv init
Install your desired Ruby version:
bash
rbenv install 3.1.2
rbenv global 3.1.2
Verify with:
bash
ruby -v
2. RVM (Ruby Version Manager)
Pros:
Also widely used and offers additional features like gemset management.
Considerations:
Some developers find that RVM’s approach (using shell functions and a more intrusive setup) can sometimes be more complex than needed.
Installation Example:
Install RVM using the installation script from the RVM website.
Follow similar steps to install and switch Ruby versions as needed.
What About URU?
URU is another Ruby version switching tool, but it’s much less commonly used on macOS compared to rbenv or RVM. Most Rails developers on macOS tend to stick with rbenv due to its simplicity, strong community support, and seamless integration with Homebrew. Unless you have a specific need or preference for URU, opting for rbenv or RVM is generally the “canonical” choice.
Conclusion
For developing a Rails app on a Mac, the best practice is to avoid using the system Ruby. Instead, install a Ruby version manager—rbenv is a particularly popular, simple, and effective option. This approach will let you manage Ruby versions, avoid permission issues, and ensure you have the flexibility to run your code in the correct environment for each project.