Installing Ruby

by Daniel Kehoe

Last updated 9 May 2016

Installing Ruby 2.2 on Mac OS X or Linux Ubuntu. Up-to-date, detailed instructions on how to install the Ruby programming language.

From the RailsApps Project

This is an article from the RailsApps project. The RailsApps project provides open source applications and detailed tutorials for developers using the Ruby on Rails web application development platform. See the article What is Ruby on Rails? for more on Rails.

For complete instructions for installing Ruby on Rails, see the article:

Follow on Twitter Follow @rails_apps on Twitter for updates and timely Rails tips.

Getting Started

You can use a hosted development environment (“in the cloud”) or install Ruby on your personal computer.

Hosted Development provides a “hosted development environment.” That means they set up a computer that you can use from your web browser. Accounts are free.

The web interface includes a browser-based file manager and text editor, plus a Unix shell with Ruby pre-installed. You don’t need to install Ruby on your computer; just use

The service is ideal for pair programming (you can connect remotely, share the same development environment, and collaborate building an application). Any computer can access the hosted development environment, though you’ll need a broadband connection.

What You Need to Know: Use if you don’t want to install Ruby on your computer.


Mac OS X comes with Ruby 1.8.7 pre-installed. You’ll likely want a newer version of Ruby.

For Mac OS X, it is best to install RVM, the Ruby Version Manager, to install Ruby and Rails. RVM provides almost everything needed to set up the components needed to install Ruby and Rails.

On Mac OS X you will need a C language compiler to install Ruby and gems that require native extensions. Install Apple’s Xcode Command Line Tools to get the correct C language compiler before you install RVM. Moncef Belyamani has written about How to Install Xcode, Homebrew, Git, RVM, Ruby & Rails.

What You Need to Know: First install Apple’s Xcode Command Line Tools. Then use RVM to install Ruby.

Ubuntu Linux

On Ubuntu, package managers are available to install Ruby. For Ubuntu Linux, it is best to install RVM, the Ruby Version Manager, to install Ruby. The package managers are often not up to date. Use RVM instead.

For developing with Rails, a JavaScript runtime is needed for development on Ubuntu Linux (it is not needed for Mac OS X or Windows). See the artcile Installing Rails for details.

What You Need to Know: Use RVM to install Ruby. Install a JavaScript runtime if you are developing with Rails.

Install Ruby Using RVM

Use RVM, the Ruby Version Manager, to install Ruby and manage your Rails versions.

Ruby may already be installed on your computer. You should install the newest version of Ruby. If you have an older version of Ruby installed you don’t need to remove it. RVM will leave your system version of Ruby untouched and use your shell to intercept any calls to Ruby. Any older Ruby version will remain on your system and the RVM version will take precedence.

On Mac OS X, you’ll need to install Apple’s Xcode Command Line Tools before installing RVM.

Install RVM

The RVM website explains how to install RVM. Here’s how:

$ \curl -L | bash -s stable --ruby

Note the backslash before “curl” (this avoids potential version conflicts).

The “—ruby” flag will install the newest version of Ruby. Ruby 2.3.1 was current when this was written. You can check for the current recommended version of Ruby.

RVM includes an “autolibs” option to identify and install components needed for your operating system. See the article RVM Autolibs: Automatic Dependency Handling and Ruby 2.0 for more information.

If You Already Have RVM Installed

If you already have RVM installed, update it to the latest version and install Ruby:

$ rvm get stable --autolibs=enable
$ rvm install ruby-2.3.1
$ rvm --default use ruby-2.3.1

Installation Troubleshooting and Advice

To start using RVM, you can either close and reopen your terminal windows or run:

$ source ~/.rvm/scripts/rvm

If you get OpenSSL errors, make sure you are using RubyGems 2.0.3 or newer:

$ gem -v

Use gem update --system to upgrade the RubyGems system gem if necessary.

For more help, see the article OpenSSL Errors and Rails.

If you get OpenSSL errors after RVM is installed, you may need to remove and reinstall RVM. Use rvm implode to remove RVM. Check that RVM has been removed with rvm -v. If it’s still there, it may be installed at the system level for multiple users. This happens if you’ve previously used RailsInstaller (on Mac OS X you’ll need to remove RailsInstaller with open /Applications/

If RVM installs successfully but installation of Ruby fails, try:

$ rvm requirements

If Ruby installation succeeds but Ruby 2.2 is not the default when you open a new terminal window, try updating the RVM loading code:

$ rvm get stable --auto-dotfiles

It is also helpful to check RVM notes:

$ rvm notes

For more information about RVM’s automatic detection and installation of system components, see:

$ rvm help autolibs

You can get help directly from the RVM team using the IRC (Internet Relay Chat) channel #rvm on

If you’ve never used IRC, it’s worthwhile to figure out how to use IRC because the RVM team is helpful and friendly. IRC on freenode requires registration (see how to register).

RailsInstaller and Alternatives

You may hear about installation programs that provide pre-assembled packages:

I don’t advise using these installer programs as they are frequently outdated. If you have problems installing RVM, use

That said, if you want to use RailsInstaller on Mac OS X, you should use the newest version available:

See instructions for Installing Rails from the Railsbridge Workshops if you use RailsInstaller. Before using RailsInstaller, be sure to remove RVM with rvm implode (or else the single-user version of RVM will hide the multi-user version of RVM installed by RailsInstaller). If you need to remove RailsInstaller, use open /Applications/ It is important to remove RailsInstaller before installing RVM because RailsInstaller installs an older version of RVM at the system level and (by default) a new install of RVM will install at the user level.

Alternatives to RVM

There are alternatives to RVM for switching between versions of Ruby. RVM is popular, well-supported, and full-featured but if you are an experienced Unix administrator, you may prefer one of the many alternatives to RVM.

Chruby provides a streamlined utility for switching between Ruby versions.

Sam Stephenson offers an alternative to RVM named rbenv. With rbenv, use Jamis Buck’s rbenv-gemset to switch between gemsets. The utilities rbenv and rbenv-gemset are less “magic” than RVM and can be useful if you encounter issues with RVM. If you want to try rbenv, see notes for installing Ruby on MacOS X 10.7.3 with XCode 4.3 and rbenv.

There are many more alternatives to RVM on this list.

Alternative Rubies

MRI, Matz’s Ruby Interpreter, is the reference implementation. It is the default when you install Ruby 2.2 using RVM. There are other Ruby interpreters available for specialized use:

Run rvm list known for a full list. Any can be installed using RVM.

Installing Rails

For more on Ruby on Rails, see the articles:


Daniel Kehoe wrote the article.

Did You Like the Article?

Was this useful to you? Follow @rails_apps on Twitter and tweet some praise. I’d love to know you were helped out by the article.

Any issues? Please leave a comment below.


Is this helpful? Your encouragement fuels the project. Please tweet or add a comment. Couldn't get something to work? For the example apps and tutorials, it's best to open an issue on GitHub so we can help you.

comments powered by Disqus