Back to blog
Apr 25, 2025
2 min read

Setting Up a Ruby Development Environment on macOS

Install ruby on macos with Homebrew

Introduction

macOS includes a system Ruby installation that should remain unmodified to prevent conflicts. This guide outlines a best-practice approach to set up an isolated Ruby environment using chruby and ruby-install, tools widely used in the Ruby community. As a Ruby developer, I’ve relied on this setup for seamless version management across projects.

Prerequisites

Install chruby and ruby-install using Homebrew:

brew install chruby ruby-install

Note: Ensure Homebrew is installed (brew.sh). Verify with brew --version.

Installing Ruby

Install Ruby 3.4.3 (or omit the version for the latest):

ruby-install ruby 3.4.3

The Ruby version will be installed in ~/.rubies/.

Restart your Terminal.

Switching Ruby Versions

Switch to the installed Ruby version:

chruby 3.4.3

Add the following to ~/.zshrc or ~/.bashrc for persistence:

source $(brew --prefix)/opt/chruby/share/chruby/chruby.sh
chruby ruby-3.4.3

Verifying the Setup

Confirm the correct Ruby version:

which ruby

Expected output: ~/.rubies/ruby-3.4.3/bin/ruby.

Check the version:

ruby -v

Installing Gems

Install Ruby gems, such as Rails:

gem install rails

Verify with rails --version.

Conclusion

This setup ensures a clean, conflict-free Ruby environment for development. Explore further with Ruby’s official documentation or start a Rails project with rails new myapp.