This is a read-only archive. Find the latest Linux articles, documentation, and answers at the new Linux.com!

Linux.com

Feature: Programming

Installing Ruby on Rails in Linux

By Drew Ames on December 04, 2008 (4:00:00 PM)

Share    Print    Comments   

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.

How to install RoR

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!

Next steps

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.

Share    Print    Comments   

Comments

on Installing Ruby on Rails in Linux

Note: Comments are owned by the poster. We are not responsible for their content.

Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 85.92.172.28] on December 04, 2008 05:06 PM
Look at passenger (formerly mod_rails) for running rails on Apache, once its installed create a virtual server and you are done.

~$ gem install passenger
~$ passenger-install-apache2-module

#

Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 24.131.41.49] on December 04, 2008 10:10 PM
There's much to like about RoRs. The list is long.

Likewise, there are a few things that need to be improved.
- memory use
- gem memory requirements

Gem is a huge. In this day of virtual servers, minimizing memory requirements goes directly towards the cost of each server environment. As a concrete example, I run Typo - a RoR blog http://typosphere.org/projects/show/typo. Since it is a relatively tiny site, we use SQLite3 for the database. No mySQL on this VM. Nothing else was installed except enough postfix and cron to manage the server. Nothing. If I don't want to swap, I can squeeze everything into 256MB. That's correct. Now, if I run gem and try to update packages, it runs for a few hours, then fails. I'm able to increase the memory to 768MB and rerun 'gem update'. Watching the memory used, it grabs over 600MB. That's just crazy, isn't it?

#

Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 122.160.32.176] on December 05, 2008 05:22 AM
Thanks for the article

#

Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 83.253.0.116] on December 06, 2008 10:17 AM
Another way is to install Netbeans 6.5 and its Ruby support.
http://www.netbeans.org/features/ruby/index.html

#

Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 12.147.219.165] on December 07, 2008 03:29 AM
Just a quick follow-up: after sending in this article, I let RDoc run for more than 15 hours, and it still hadn't finished with the Rails gems. I suspect that my Pentium III computers simply can't handle RDoc, although I have good, working installations of RoR.

-Drew Ames

#

Re: Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 66.92.86.225] on December 07, 2008 03:37 AM
Urr - so don't have it install rdoc or ri.

gem install --no-rdoc --no-ri blah

#

Re(1): Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 70.91.34.61] on December 08, 2008 03:06 PM
That's effectively what I did, but thanks for pointing out the command. I simply cancelled the RDoc process.

#

Installing Ruby on Rails in Linux

Posted by: Anonymous [ip: 218.219.203.156] on December 11, 2008 07:50 AM
Gem is made by someone who can't code well obviously. Those rdoc and whatnot takes like forever and does eat up like 500MB (It chokes up my Linux under VMWare, because I only give it 200MB ram, which is enough for everything else to run a personal development Linux server), which is insane. Hopefully someone who can actually code fix it.

#

This story has been archived. Comments can no longer be posted.



 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya