Ruby on Rails Install and Intro
This page shows you how to install Ruby on Rails, and some basic info about Rails.
Ruby On Rails's official site is http://rubyonrails.org/
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?
- 2.3 →
- 3.0 →
- 3.1 →
- 3.2 →
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.
- Ruby 1.6 →
- Ruby 1.8 →
- Ruby 1.9.1 → (major change. Not compatible with 1.8)
- Ruby 1.9.3 →
- Ruby 2.0.0 → . 100% compatible with 1.9.
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
Error when you don't have sqlite installed
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
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
Error for no JavaScript engine installed
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 https://github.com/sstephenson/execjs 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
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 http://nodejs.org/ 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.