- About Us
Ruby on Rails is garnering a lot of praise as an easy-to-use, database-driven Web framework for developing Web applications. Most of the documentation for Ruby on Rails centers on Macintosh, with the remainder seemingly only for Windows machines, but RoR is perfectly usable on Linux computers too. This article explains how to install and begin developing with RoR in Linux.
RoR represents a convergence of two trends: the emergence and rise of Ruby as a programming language, and the push for database-driven Web sites with Web 2.0 features. Ruby is an object-oriented, dynamic, interpreted programming language developed in Japan in the mid '90s. Rails (first released in 2005) is a framework written in Ruby that ties together a database and a Web server.
Dynamic database-driven Web sites provide user interaction beyond static and dynamic Web pages that use only client-side scripting. Database-driven Web sites use scripts or programs on the server to interact with data stored in a database to provide a rich interactive environment. Web forums, e-commerce sites, blogs, wikis, and various social networking sites are all examples of database-driven Web sites.
RoR is unique not because it results in a database-driven Web site, but in how it streamlines development of the site. RoR creates a framework consisting of a directory structure and several scripts with all of the code required to create a model (the database), the views (Web pages for interacting with the database), and the controllers, which connect the model and the views. RoR takes a lot of the burden of database management and server programming off Web developers.
Best practices for RoR developers call for them to do all development on their local machines. This requires a Web server, database program, Ruby, and Rails. Installing RoR involves using RubyGems, which is a package manager for Ruby libraries. Rails, and a few other necessary items, are really just libraries, and Gems makes installing them mostly painless. Debian package maintainers have expressed concern about using a package manager other than the distribution's own. However, using Gems is much easier than installing from source and tracking versions or dependencies by hand, and the Gems repositories are more up-to-date than the Debian ones.
I installed RoR on two computers running Slackware 12.1. The community documentation for Ubuntu has instructions that are similar to the procedure I used for Slackware. If, as I did, you use Gems for the package manager, the procedure should be similar regardless of the distro you use.
You must perform all installation steps either as the root user or with root privileges via sudo. You must install RubyGems from a virtual terminal.
The first step is to install Ruby. The Ruby on Rails Web site recommends Ruby version 1.8.6. Most distributions, if they don't install Ruby by default, provide it in their repositories.
The next step is to install a database. RoR can use SQLite, MySQL, or PostgreSQL; its default is SQLite. I used the Slackbuild script for SQLite 3.6.2 from Slackbuilds.org -- a process made easier by using Sbopkg.
Next, install RubyGems. I used the SlackBuild script for RubyGems 1.3.1 found at SlackBuilds.org. Most distributions can install a database and RubyGems using native package management tools.
Once RubyGems is installed you can install the rest of RoR. To install Rails 2.2, the latest release, with RubyGems, type:
gem install rails.
One problem with RubyGems is that it is not very verbose. You get messages after installation tasks are completed, or if there is an error, but not while things are going on. Successful installation gives this message:
Successfully installed activesupport-2.2.2 Successfully installed activerecord-2.2.2 Successfully installed actionpack-2.2.2 Successfully installed actionmailer-2.2.2 Successfully installed activeresource-2.2.2 Successfully installed rails-2.2.2 6 gems installed
After the packages are installed, Gems immediate installs their documentation. For some reason, installing the RDoc documentation took a very long time on my computers, and there are no messages to indicate what Gems is doing during that time. After more than three hours I cancelled the procedure, which left a working Rails installation, but one without documentation. I plan to attempt to reinstall the documentation later. Meanwhile, Rails still needs two more things: a Web server and a way to interface with the database.
If you need to install a Web server, you have a couple of choices. RoR can use a number of different servers, but I went with the default of Mongrel, a Web server written in Ruby that RubyGems can install with the command
gem install mongrel. I then installed the SQLite adapter with
gem install sqlite3-ruby.
At this point, you've got a working RoR installation that all users on your computer can use. Switch from the root user to your own unprivileged account and open a virtual terminal. Test your RoR installation by typing
rails test. This command will create a Rails framework in a directory called test in your home directory. This is where all the magic happens.
Change to the ~/test directory and type
script/server to start the Mongrel Web server, then point your Web browser at http://localhost.3000. If everything has gone well, you should see the Ruby on Rails "Welcome aboard" Web page. Switch back to your virtual terminal, press Ctrl-C to stop the Web server, and you're ready to start developing with RoR!
Once you have a working RoR framework you're ready to start learning how to use it. The Ruby on Rails guides are a great resource. Follow them in order and you'll have a working site in very little time. I also recommend the book Rails Up and Running, 2nd Edition. It was published on October 2008, so is very up-to-date. Like the RoR guides, the book takes you through the process of setting up an application, but it also has a lot of explanatory information on how Rails work. The book is aimed at Web developers who are new to Rails and possibly Ruby. I found that reading each chapter, then going through the exercises, then reading the chapter again, greatly enhanced my understanding.
If you are not running your own Web server, and you are looking for a Web host, check out RailsHosting.org to learn more about commercial Web hosting services that specialize in RoR.
The RoR Web development framework is very friendly to Linux, and RoR works the same in Linux as in other OSs, so the extensive available documentation is applicable to Linux installations. RubyGems is a comprehensive and easy-to-use package manager that seems to work well alongside a distro's own package manager. Once you have it installed, RoR really does simplify and streamline the development of dynamic, database-driven Web sites.
Drew Ames is a transportation planner in Harrisburg, Penn.