Rails framework is the most popular web application development framework for Ruby language. It is a cross-platform library which supports Windows, Linux, and macOS. In this article, I will discuss how to install Rails on macOS step by step. Let’s get started.

Instructions on how to Install Rails on macOS:

Before getting started, you must know that your macOS must have the Ruby pre-installed. Apple already provides us with a pre-installed Ruby version. However, you must update it on their official website. If you do not have Ruby installed or do not have the latest released version, do see the post highlighted below and then follow this tutorial.

Also, Read | How to Install Ruby on macOS? Step by Step Guide

If you already have the latest version of Ruby installed on your mac then follow the following steps:

Step 1. Open Terminal(cmd+Space) and type “gem install rails”. In most cases, it will work and you are done.

However, there could be some problem that you might face as shown below.

problem in install rails on macOS
Problem: you don’t have the permission to run this command

This is because macOS won’t let you change anything with the Ruby version that comes installed with it. But, you can install gems using a separate version of Ruby that doesn’t interfere with the one provided by Apple.

So, if this pops up on your terminal then, you have to modify the “path file” of Ruby so that you have the necessary permissions to run the above command.

How to Solve “You don’t have write permissions for the /Library/Ruby/Gems/2.3.0 directory”

Step 2. Run the following command to check which version of Ruby is being accessed when you run the above command.

which ruby -- this command will return something like /usr/bin/ruby followed by,
ruby -v -- this command should return something like ruby 2.3.7 or 2.6.1 what ever the case may be.

Step 3. Install a separate version of Ruby(ignore if you already have the updated version). Then, update your “PATH”. The path is the list of directories in which the computer looks them. Type “echo $PATH” and you will see the list of directories, separated by a colon.

There are many ways to install Ruby. If you have installed Ruby using the Homebrew then follow the 4th step. If you don’t have any idea then please see the “How to Install Ruby on macOS? Step by Step Guide” linked above and then follow from here.

Step 4. Once Homebrew and ruby are installed, then update your path by running the following command.

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile, followed by 
source ~/.bash_profile

then run the “gem install rails” command now and you are done. You should see something like this on your terminal.

install rails on macOS
This will install about 41 gems and you are ready to use the Rails framework

If you follow the steps, I hope you should not face any difficulty in installing the Rails on macOS.

TIP: There are many ways to install Ruby on a Mac but the best way is to install using an automated script that will set up a proper Ruby environment for you and then you can easily install Rails later on.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.