Recommended Approach:
The canonical way to use Ruby on Macs for developing a Rails app is to use a version manager like rbenv or rvm (Ruby Version Manager). This approach provides flexibility and isolation for your Ruby environments.
Why not the default install?
The default Ruby installation on Macs is often outdated and may not be suitable for the latest Rails versions. Using a version manager allows you to easily switch between different Ruby versions and manage dependencies for your projects.
Comparison of Version Managers:
rbenv: A lightweight, simple, and widely-used version manager.
rvm: A more feature-rich version manager with additional tools for managing dependencies and environments.
uru: A Ruby version manager that allows you to install and manage multiple Ruby versions, but it's not as widely used as rbenv or rvm.
Step-by-Step Setup:
Install rbenv:
Using Homebrew: brew install rbenv
Using the installer script: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash
Install the desired Ruby version:
List available versions: rbenv install --list
Install a specific version: rbenv install <version> (e.g., rbenv install 3.1.2)
Set the global Ruby version:
rbenv global <version> (e.g., rbenv global 3.1.2)
Install Rails:
gem install rails
Create a new Rails app:
rails new myapp
Example Use Case:
Suppose you want to develop a Rails app using Ruby 3.1.2. You can install Ruby 3.1.2 using rbenv, set it as the global version, and then install Rails.
bash
# Install Ruby 3.1.2
rbenv install 3.1.2
# Set Ruby 3.1.2 as the global version
rbenv global 3.1.2
# Install Rails
gem install rails
# Create a new Rails app
rails new myapp
By following these steps, you'll have a clean and isolated Ruby environment for your Rails app, making it easier to manage dependencies and switch between different Ruby versions as needed.