References : http://railsapps.github.io/installrubyonrails-ubuntu.html
Prepare Your System
You’ll need to prepare your computer with the required system software before installing Ruby on Rails.
You’ll need superuser (root) access to update the system software.
Update your package manager first:
$ sudo apt-get update
This must finish without error or the following step will fail.
Install Curl:
$ sudo apt-get install curl
You’ll use Curl for installing RVM.
Install Ruby Using RVM
Use RVM, the Ruby Version Manager, to install Ruby and manage your Rails versions.
If you have an older version of Ruby installed on your computer, there’s no need to remove it. RVM will leave your “system Ruby” untouched and use your shell to intercept any calls to Ruby. Any older Ruby versions will remain on your system and the RVM version will take precedence.
Ruby 2.3.0 was current when this was written. You can check for the current recommended version of Ruby. RVM will install the newest stable Ruby version.
The RVM website explains how to install RVM. Here’s the simplest way:
$ \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.
RVM includes an “autolibs” option to identify and install system software 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
$ rvm --default use ruby-2.3.0
Installation Troubleshooting and Advice
RVM Troubleshooting
If you have trouble installing Ruby with RVM, you can get help directly from the RVM team using the IRC (Internet Relay Chat) channel #rvm on irc.freenode.net:
http://webchat.freenode.net/?channels=rvm
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).