Mojave: Ruby and Rails - [003]

Setting up Ruby / Rails can be quite a challenge, in this episode we'll walk you through the process so you can get up and running with ruby and rails as fast as possible. Make sure you have asdf-vm installed if you haven't check out our previous episode

Installing ASDF Ruby Plugin

We'll need to install the asdf plugin for ruby.

asdf plugin-add ruby

This should setup the ruby plugin for us.

Installing Ruby

We can list out the different version of ruby by typing

asdf list-all ruby

Let's install ruby version 2.5.1

asdf install ruby 2.5.1

This will download and compile ruby for us.

Configuring Ruby

We'll need to do a reshim using asdf and use the version we want to use.

asdf reshim ruby 2.5.1

Let's set the version

asdf global ruby 2.5.1

This will set ruby 2.5.1 as the global default version on our system. You can also set the version locally on a per project basis using

# in the project direcoryasdf local ruby 2.5.1

Now that we've changed the ruby version launch a new terminal session (new window or new tab cmd + t ).

Verifying our Setup

We can verify our ruby version by typing

ruby -v

It should show 2.5.1 in the output.

Adding Shims to the $PATH

We need to add the ruby shims to the path by modifying the ~/.zshrc . You can type which gem and it will show you the path of the shims copy /usr/local/opt/asdf/shims and add

# in ~/.zshrcexport PATH=/usr/local/opt/asdf/shims:$PATH

Now we can run source ~/.zshrc

This will add the shims to the path which means we'll able to run ruby bins without specifying the path.

Installing Rails

We can now finally install rails

gem install rails

Once this is done we can launch a new tab or open a new session to re-initialize the environment

Generating a new Rails App

Once everything is setup we can simply generate a new rails app

rails new example

This will generate a new project called example . Go into the directory and launch rails

rails s

That's it! We're all done simply browse to localhost:3000 to hit our rails app and verify that everything is working.