-
Notifications
You must be signed in to change notification settings - Fork 3
install ruby
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.
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 @rails_apps on Twitter for updates and timely Rails tips.
You can use a hosted development environment (“in the cloud”) or install Ruby on your personal computer.
Nitrous.io 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 Nitrous.io.
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 Nitrous.io 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.
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.
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.
The RVM website explains how to install RVM. Here’s how:
$ \curl -L https://get.rvm.io | 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, 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
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/RailsInstallerOSX-Uninstaller.app
).
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 irc.freenode.net:
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).
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 Nitrous.io.
That said, if you want to use RailsInstaller on Mac OS X, you should use the newest version available:
http://railsinstaller.s3.amazonaws.com/list.html
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/RailsInstallerOSX-Uninstaller.app
. 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.
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.
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.
For more on Ruby on Rails, see the articles:
Daniel Kehoe wrote 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.