Back
Chapters

Installing Ruby on Rails

Search icon
Search Book
⌘K

Before moving ahead with this section make sure that you are using the Intel build of brew. For that, you can to refer to Uninstall arm64 brew section of the book. Also make sure you had installed Xcode command line tools as we had mentioned in previous chapter.

Install system packages

Ruby needs certain system packages like Openssl for it to be compiled properly. Thus install the following packages from the Rosetta enabled terminal:

1brew install ruby-build openssl readline libyaml zlib

Install rbenv

Install rbenv. Using rbenv we can install a specific version of Ruby:

1brew update
2brew install rbenv

If you don't know which shell you are using then refer to this answer.

If you are using zsh shell then use the following command:

1echo 'eval "$(rbenv init -)"' >> ~/.zshrc

If you are using bash shell then execute the following command:

1echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Now restart the terminal and run the following:

1rbenv install 3.0.4
2rbenv rehash

Add ~/.rbenv/bin to your $PATH for accessing the rbenv command-line utility.

If you are using bash shell then execute the following command:

1echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile

If you are using zsh shell then use the following command:

1echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc

Restart the terminal and rbenv should be available as a command.

It's often seen that folks have a Ruby version conflicts in their system. It's mostly because Ruby gets installed by default on the system level. But system-level ruby command has different permissions and paths, compared to the ruby command installed via rbenv.

Thus let's set the global version of the ruby command to be a rbenv specific version, like so:

1rbenv global 3.0.4

Now that we have set the global Ruby version to be an rbenv specific version, let's verify the same, by running the following commands:

1rbenv version # version should be 3.0.4
2ruby -v # version should be 3.0.4

In M1 Mac, we need to install the shared mime info, if it doesn't already exist:

1brew install shared-mime-info

Installing Ruby on Rails on macOS

Now install Ruby on Rails gem:

1gem install rails --no-document -v 7.0.3.1

Flag --no-document disables document generation.

Now install bundler which help us manage Ruby gems:

1gem install bundler

Installing Ruby on Rails in other operating systems

At BigBinary we use Mac.

Thus, we won't be documenting on how to install Ruby and Ruby on Rails on Windows/Linux.

There are plenty of good materials on the internet and on YouTube about installing Ruby on Rails and setting up the work environment on Windows/Linux.

TypeError for Rails project in M1 Mac

If you ever receive the TypeError: Unable to resolve type 'size_t' error while working on a Rails project in M1 Mac, then run the following command to fix it:

1bundle update ffi sassc

Rbenv Ruby build definitions not found error

Rbenv Ruby build definitions not found error is thrown if ruby-build is not installed. ruby-build is an rbenv plugin that provides the rbenv install command to compile and install different versions of Ruby on UNIX-like systems.

You can check if ruby-build is installed system-wide under homebrew using which command like so:

1which ruby-build

If ruby-build already installed, then the following installed path should show up in the terminal:

1/usr/local/bin/ruby-build

Otherwise you will receive the following error:

1ruby-build not found.

If ruby-build is not installed, then you should install it like so:

1brew install ruby-build