Last Updated:

Rails Intro, Deep Dive: Installing Rails, Part One

Continuing my last post about RVM, this time we'll install Rails. Again, this series attempts to give you a deeper understanding of how to get started with Rails, so we'll look at some of the options available when you first create your world-changing Rails application, as well as the gems that are installed with Rails.

Choosing a translator

First of all, make sure you open the terminal and switch to our Ruby RVM interpreter and gem set, i.e. MRI 1.9.2 and rubysource, respectively. We do this with

rvm 1.9.2@rubysource

and you can check with quick RVM info. As you probably know, the way to create a new Rails application is to type it at the command prompt.

rails new applicationName

Installing Rails

You may not know where the Rails executable is located. In fact, it may surprise you that the only thing that the Rails gem includes is the rails executable. The Rails gem has many dependencies that are satisfied by other gemstones, but the actual Rails gem is just an executable file. Let's set it up now.
gem install rails --pre



The --pre option instructs RubyGems to install the latest available gem, which may not be the "official" stable version of Rails. In our case, we get Rails 3.1 RC4. "RC4" stands for "Release 4 Candidate," which should be the last of the release candidates before Rails becomes stable, which is another way to say it's released. We can see the overall release cycle that Rails follows by looking at the tags on Github.

ere we can see that Rails follows a pattern starting with a "beta" followed by 4 or 5 release candidates before it becomes stable. With RVM, we can mess up any pre-release software without polluting the rest of the development environment.

Now you know what the "-pre" option does when installing Heme Rails, but what other options are there? "Gem install" takes a lot of options, which we can see here.


RubyGems allows us to specify elements such as a specific version (which we've seen), the installation destination, whether or not to install documentation, whether or not to install dependencies, and to specify a source for gem searches. By looking at the available options, it's easy to see how RVM uses RubyGems to isolate gem sets. Finally, you can put any of these options in your ~/.gemrc file if you enter the same parameters over and over again. As a special bonus, here's a way to significantly speed up the installation of your gems by setting parameters in the Gem configuration file.

Other gemstones set

When we installed Rails, he also installed a few other gems. What are these gemstones? What is their purpose?




Gemstones installed with Rails

Let's take a quick look at each of them.

MultiJSON (from Intridea, which does great things) allows you to use multiple JSON backends, identifying and using the best one. In the case of installing vanilla Rails, a gem json_pure is used.

ActiveSupport is "a collection of various utility classes and standard library extensions that have been found useful to Rails. So all of these add-ons are put together in this package as a way to collect all the sugar that makes Ruby sweeter." This means that ActiveSupport is the building blocks of Rails, including abstractions for caching, JSON support, Unicode support, and notifications. It also defines ActiveSupport :: Railtie, which is one way to extend your Rails application. The latitude of ActiveSupport is too great to cover, so check it out in your spare time.

provides a domain-specific language (DSL) for creating markup.

The i18n
Gem i18n provides all localization support for Rails. As you can imagine, this is a big topic and worth exploring as your knowledge of Rails grows.

BCrypt Ruby
BCrypt is a novelty in Rails 3.1 that provides encryption to protect permanent passwords.

ActiveModel provides an interface for models in Rails. ActiveModel was provided starting with Rails 3.0, allowing the developer to go through the breadboard string of syntactic sugar provided to models in Rails and place only the right bits on the plate.

Gemstone rack.
Rack provides an interface to the web server from Ruby applications. One of the elements supported by Rack is middleware, which allows bits of code to be passed to the web request/response pipeline and provide functionality. rack-cache is a middleware that enables HTTP caching. rack-test. provides an API for testing Rack applications (what Rails is) as a pretty DSL. Rack-mount provides routing for Rails that manages the nice RESTful interface of a standard Rails application.
Hiking The hike handles the loading and search paths for Rails.

Tilt Tilt
provides an interface for various Ruby template engines such as ERB and Haml.

Sprockets is
new in Rails 3.1, providing a new resource packaging pipeline for javascript and coffeescript, as well as for SASS and CSS.

TZInfo is a time zone library for Ruby.

Well, this post reaches a point where it can't be read on a train or wait at a dentist, so I'm going to split the gem descriptions into two posts. We'll take the Erubis gem next time. I hope you find this approach to rails training and learning. As always, if you want to improve the article or add insight, please leave a comment.