Exploring Ruby on Rails as a Laravel Dev: Setup (Part 1)

As a Laravel developer, I’ve gotten used to the smooth setup process, clear documentation, and resources like Laracasts to guide me through every step. So when I decided to try Ruby on Rails, I went in with expecting a similar experience.

It turned out to be a little less easy than that: The Rails setup wasn’t as simple—especially when it came to finding a single, definitive guide. In this post, I’ll walk you through my journey setting up Ruby on Rails on macOS, the challenges I encountered, and how I finally got everything working.

Attempt #1: Built-in Ruby (failed)

I started out by checking whether Ruby was already installed on my Mac:

$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin24]

And... it actually was!

I continued by checking out the installation section of the Rails documentation. SQLite was the next prerequisite, which I already installed. So it was just a matter of installing Rails:

$ gem install rails
...
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

Dang. Perhaps the built-in version isn't the way to go? I assumed it wasn't.

Attempt #2: Ruby using Brew (almost)

Next, I naturally turned to Homebrew, the go-to macOS package manager, to install Ruby and Rails. Here’s how that went:

$ brew install ruby

That installed version 3.3.5. All right! I proceeded to install Rails:

$ gem install rails
...
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

Wut. Argh, I didn't read the installation hint from Brew. Add Ruby to the path:

$ echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

And... try again:

$ gem install rails
...
39 gems installed

Better! So at this point, I wanted VS Code, my IDE, to work with Ruby files. It was just a matter of installing the Ruby LSP extension.

This is where I hit my second roadblock. I couldn't get it working - it kept telling me it couldn't establish a connection to the LSP server. I went for a different angle.

Attempt #3: Ruby using Chruby (success)

After diving into some Ruby setup guides (which were scattered across different sites), I learned that many Ruby developers rely on version managers like chruby to avoid the kind of issues I was facing. It’s similar to how Laravel developers might use Valet or Homestead to manage local development environments.

First, I removed the Brew version I installed earlier.

Here’s how I finally got Ruby and Rails set up correctly using chruby:

$ brew install chruby ruby-install

This showed me the latest stable Ruby version available for installation:

$ ruby-install --latest

I then installed the latest Ruby version using:

$ ruby-install --latest ruby

After installing Ruby, I needed to set up chruby in my terminal by adding these two lines to my .zshrc file:

source /usr/local/opt/chruby/share/chruby/chruby.sh
source /usr/local/opt/chruby/share/chruby/auto.sh

I restarted my Terminal. With Ruby properly set up, I reinstalled Rails:

$ gem install rails

I then fired up VS Code and everything worked!

Summary

One thing I noticed during this process was the lack of a single, well-maintained guide for setting up Ruby on Rails. In the Laravel ecosystem, we’re lucky to have amazing resources like the Laravel documentation and Laracasts, where everything is centralized and clearly explained. For Rails, I had to piece together different guides, blog posts, and forum answers to get everything working.

But that's ok, it wasn't rocket science.

That’s it for the installation journey! In Part 2, I’ll dive into building my first Rails app and share my thoughts on how the framework compares to Laravel in terms of actual development. Stay tuned!

Clicky