CodeNewbie Community 🌱

Cover image for 49 Days of Ruby: Day 2 - Installing Ruby
Ben Greenberg
Ben Greenberg

Posted on • Originally published at on

49 Days of Ruby: Day 2 - Installing Ruby

Welcome to day 2 of the 49 Days of Ruby! πŸŽ‰

Today we are going to install Ruby locally on your machine. We can't move forward with the upcoming topics if we don't have Ruby to work with, right?

It's quite possible that you already have a version of Ruby locally available on your machine. However, most often, that Ruby version is out of date.

For today we are going to learn how to install Ruby version manager on your computer, and how to use it to install and manage your Ruby versions (or Rubies, if you will).

The steps below are based on a Mac, if you are using Windows check out the RubyInstaller application to get you started.

Ruby Version Manager

We are going to use rbenv for our Ruby version manager.

To install rbenv let's use Homebrew:

$ brew install rbenv

Enter fullscreen mode Exit fullscreen mode

Once that command finishes, you can initialize rbenv by executing rbenv init from your command line. If you're curious you can see exactly what rbenv init does in the README.

You will need to open a new terminal window once initialization has finished.

In a new terminal window you can verify everything worked by running the rbenv-doctor script. To do so according to the README:

$ curl -fsSL | bash

Enter fullscreen mode Exit fullscreen mode

You should see a few lines of output after that execution verifying that rbenv is installed.

You're now ready to install the current version of Ruby on your system!

Installing Ruby

To use rbenv to install the latest version of Ruby you want to first identify the latest stable version available. You can do so by running rbenv install -l from the command line.

For example, if the latest stable version of Ruby is 3.0.0, then you can install it by running:

$ rbenv install 3.0.0

Enter fullscreen mode Exit fullscreen mode

You can also use rbenv to set the version of Ruby you are using, in addition to installation. Once you have installed the latest stable version, let's say it is 3.0.0, you can set your global Ruby version on your system for use with:

$ rbenv global 3.0.0

Enter fullscreen mode Exit fullscreen mode

You could also just do it for this specific shell, if you'd like by using shell in place the global keyword.

At this point, if you check your Ruby version with ruby -v from the command line you should see 3.0.0.

That's it for today! You have successfully installed a Ruby version manager and the latest stable version of Ruby. See you tomorrow for day three!

Come back tomorrow for the next installment of 49 Days of Ruby! You can join the conversation on Twitter with the hashtag #49daysofruby.

Top comments (0)