Guide to Getting Started with Ruby

Are you developing on a Windows or Linux computer?

Then this guide will not work for you. These things might:

Okay, you’re a Mac user. Have you ever used your Terminal before?

Yes? Okay, you’re good to go.

No? Don’t go any further before learning about your Terminal. Here’s resources to get you started:

Note: the terms command line, command-line, command line interface (CLI), terminal, shell, and bash all mean the same thing: a text-based interface to your computer where you can run bash code.

Part 0: What we’ll be doing

You’ve decided to get started with Ruby on your local computer. Awesome! Ruby is a great back-end language with a lot to recommend it, not the least of which is a mature ecosystem of tools and communities.

Here’s the process this guide will take:

READ YOUR TERMINAL OUTPUT. If there are any errors, they will be obvious, and you need to respond correctly to them.

Part 1: Installing a package manager

Open your terminal. Install Homebrew, a package manager, by pasting the following code into your prompt:

/usr/bin/ruby -e "$(curl -fsSL"

This might prompt you for your password. Type in your password–it won’t show anything as you type, but it will be listening nevertheless. Press enter to continue.

It’ll take some time to finish installing, don’t continue until your prompt returns.

Review the output to make sure there were no errors and the process of installing didn’t stop or break/error out.

Part 2: Installing rbenv, a Ruby version manager

Check if you already have rbenv installed by inputting the following command in your terminal:

rbenv -v

The -v flag usually stands for version or verbose, which means, “show me information about this program”. If you get output like rbenv 1.1.0, you already have it installed, so move on to the next part.

If you don’t have rbenv installed, input the following command:

brew install rbenv

Check the output to make sure everything installs as expected.

Part 3: Installing Ruby with rbenv

In the terminal, type the following:

rbenv install 2.6.0

This command tells rbenv to install Ruby, specifically Ruby version 2.6.0. There are other versions, but this is a good, current version (as of Jan 18, 2017).

This will also take some time.

Part 4: Configurations

When your rbenv is done installing Ruby, run the following code:

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

There won’t be any output when you run this command.

Now, let’s set the correct Ruby version to be used whenever you want to write some Ruby code and run it:

rbenv global 2.6.0

This means, “Set the global version of Ruby in this computer to be 2.6.0”.

Finally, run the following code:

gem update --system

This will update where your gems will download, making sure they will always download to a subfolder within the Ruby 2.6.0 version, which will allow you access. This will also ensure you have the most recent version of rubygems installed on your computer, to allow you to download gems from here on.

Part 5: Download a gem to test that everything works

Quit and reopen your terminal.

Run the following code to download pry, a great gem used to pause programs in the middle in order to inspect values:

gem install pry

If nothing errors out, and you get some output like 4 gems installed, you’re all set! You now have Ruby installed and can be on your merry way.

You’re done!

You can write Ruby files on your computer now. Here’s a list of things to try out: