Ruby on Rails Install and Intro

By Xah Lee. Date: . Last updated: .

This page shows you how to install Ruby on Rails, and some basic info about Rails.

Ruby On Rails's official site is

Before you start, you should read: What is RVM, Gem, Rake, Bundler, RDoc, ri, irb? .

How to find out if Rails is installed?

In terminal type rails. It'll print a help page. If not found, then it's not installed, or it's not in the environment variable named $PATH.

What version is my Rails?

Type rails --version

What are the versions of Rails?

Rails 3.2 is the last version that supports Ruby 1.8.7.

You should use Ruby 1.9.x, because 1.9 is a major version. It is not compatible with 1.8.x.

What are the major versions and release date of Ruby?

Here's major Ruby versions release date.

How to install Rails?

To install Rails, first you need to install Ruby, then use RubyGems to install Rails, like this:

sudo gem install rails

do not use linux apt-get to install, because that's usually too outdated

[see Ruby: What's RVM, Gem, Rake, Bundler, RDoc, ri, irb?]

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/xah/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or 'yum install sqlite-devel' and check your shared library search path (the
location where your sqlite3 shared library is located).
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

        ERROR: Failed to build gem native extension.
        /home/xah/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb
Error when you don't have sqlite installed.

Solution: sudo apt-get install libsqlite3-dev sqlite3.

To be safe, run the following to install many common packages needed by Rails.

sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config
home/xah/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See for a list of available runtimes. (ExecJS::RuntimeUnavailable)
	from /home/xah/.rvm/gems/ruby-1.9.3-p327/gems/execjs-1.4.0/lib/execjs.rb
Error for no JavaScript engine installed.

What JavaScript engine to install?

To run Rails, you'll need a JavaScript engine. I recommend Node.js. Just go to Node.js's home page at and get the source code and compile it. Should have no problem.

What are the Rails commands?

Type rails --help. Sample output:

◆ rails --help
Usage: rails COMMAND [ARGS]

The most common rails commands are:
 generate    Generate new code (short-cut alias: "g")
 console     Start the Rails console (short-cut alias: "c")
 server      Start the Rails server (short-cut alias: "s")
 dbconsole   Start a console for the database specified in config/database.yml
             (short-cut alias: "db")
 new         Create a new Rails application. "rails new my_app" creates a
             new application called MyApp in "./my_app"

In addition to those, there are:
 application  Generate the Rails application code
 destroy      Undo code generated with "generate" (short-cut alias: "d")
 benchmarker  See how fast a piece of code runs
 profiler     Get profile information from a piece of code
 plugin       Install a plugin
 runner       Run a piece of code in the application environment (short-cut alias: "r")

All commands can be run with -h (or --help) for more information.

Ruby Tutorial







Loop, Iteration

Data Structure