Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(’The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

July 22, 2008

Setting Up Rails Development Environment on Ubuntu GNU/Linux

Filed under: Ruby/Rails, Ubuntu — tabrez @ 7:38 pm

This is an adaptation to Ubuntu GNU/Linux platform of my previous post which was meant for the Windows platform: Setting Up Rails Development Environment on Windows Vista/XP

I can think of two different ways in which you might want to set up a development environment for Ruby on Rails on a GNU/Linux machine. One is to download everything outside of the package manager of your distribution i.e. build everything from the source. I am going to cover the second, easier way: how to setup Rails on a Debian/Ubuntu machine using its package manager for the most part. I show below how to setup Ruby, RubyGems, Rails, Mongrel, MySQL, and Subversion as part of the development stack.

  1. Installing Ruby:

    If not already installed, install the build-essential package first:

    # sudo aptitude install build-essential

    Then install the Ruby and related packages:

    # sudo aptitude install ruby irb ri rdoc rake libopenssl-ruby libsqlite3-ruby ruby1.8-dev
  2. Installing Rubygems

    Though it is possible to install Rubygems using the Ubuntu package manager, not only will you get an old version of rubygems if you do so, it also may not be compatible with the latest version of rails. I strongly recommend you download the source code package of the latest version of rubygems and install it using its setup script:

    # cd $HOME
    # wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
    # tar xvzf rubygems-1.2.0.tgz && cd rubygems-1.2.0
    # sudo ruby setup.rb

    Debian purists may frown at installing packages all over the system directories outside of control of the package manager. See Debian’s position on Rubygems. [via - RailsOnUbuntu]
    Remember to download the latest version of rubygems available(currently 1.2.0). You can remove the downloaded tgz archive and the extracted directory after the installation is finished.

    #cd $HOME
    # rm -r rubygems-1.2.0.tgz rubygems-1.2.0

    If Ubuntu complains that the ‘gem’ command is not found, you may have to create a symbolic link like this:

    # sudo ln /usr/bin/gem1.8 /usr/bin/gem

    You can update the rubygems package by running the following command:

    # sudo gem update ––system
  3. Installing Rails

    The final step is to install the Rails gem package itself.

    # sudo gem install rails

    This will install the latest Rails version on your Ubuntu GNU/Linux. If you ever want to update Rails in the future, just run the following command:

    # sudo gem update rails

    You can update the other packages using Ubuntu’s package management tools(aptitude) since that is how you installed those packages in the first place.

The basic Rails development environment is now installed on your system and you can skip the rest of the post if you are happy with WEBrick as the web server, SQLite as the database server and your favourite text editor/IDE that may be already installed on your system. The following instructions cover installing an alternate web server called Mongrel; MySQL database server and its GUI tools; and Subversion.

  1. Installing Mongrel

    Installing the Rails gem also installs the WEBrick web server which is ideally suited for development purposes. Another much recommended web server for Rails development as well as production environment is the Mongrel web server. To install the Mongrel web server, run the following gem command:

    # sudo aptitude install mongrel

    After installing Mongrel, Rails automatically starts the Mongrel instead of WEBrick web server when you run the Rails applications in development mode. (Refer to Mongrel documentation to know more about runing Rails applications under Mongrel in production mode.)

  2. Installing MySQL

    This step covers the installation of MySQL database server and its GUI tools. Skip this step if you want to use some other database server. Run the following command to install the required mysql packages:

    # sudo aptitude install mysql-server mysql-admin mysql-query-browser

    One important step during the configuration process is to select a root password(you will need to enter it in the database.yml configuration file of your Rails application).

  3. Installing Subversion

    Finally, install your favourite revision control software - CVS, Subversion, git etc. You can install subversion in this way:

    # sudo aptitude install subversion

Now you can create/checkout Rails applications, edit the files using your favourite text editor/IDE and run it under Mongrel. In future, I will try to write about developing Rails applications using integrated development environments like Eclipse and NetBeans.


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • Setting Up Rails Development Environment on Fedora GNU/Linux
  • “Hello, World” Web Application in Ruby on Rails using console
  • Installing Sun Java SE 6, Apache Maven 2 and Tomcat 5.5 on Ubuntu GNU/Linux
  • Setting Up Rails Development Environment using Aptana Studio
  • “Hello, World” Web Application in Ruby on Rails using Aptana Studio
  • Installing Grails in Ubuntu GNU/Linux Using Package Manager
  • Setting Up Ruby on Rails Projects with Git and Github

  • Readers who viewed this page, also viewed:


    4 Comments »

    1. Probably also want to install git (since a lot of rails devs use it now), sqlite3 (default rails db, great for speedy autotest) & passenger (easiest deployment for rails) all below require su privs (aka sudo su):

      aptitude install git libsqlite3-dev apache2-mpm-worker apache2-prefork-dev libapr1

      gem install sqlite3 passenger

      passenger-install-apache2-module

      echo “LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so” > /etc/apache2/mods-available/passenger.load

      cat < /etc/apache2/mods-available/passenger.conf
      PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.2
      PassengerRuby /usr/bin/ruby1.8
      EOF

      cat </etc/apache2/sites-available/default

      ServerName localhost
      DocumentRoot /path_to_rails_app/public

      EOF

      a2enmod passenger

      apache2ctl configtest

      apache2ctl graceful

      if you have multiple rails apps you can setup your /etc/hosts file to point each app name @ 127.0.0.1 and use that name in the virtual host “ServerName” declaration

      Quote

      Comment by Mark — July 25, 2008 @ 4:13 am

    2. it looks like my HEREDOC’s got butchered. blah

      Quote

      Comment by Mark — July 25, 2008 @ 4:14 am

    3. [...] Setting Up Rails Development Environment on Fedora GNU/Linux Filed under: General — tabrez @ 10:52 pm This is an adaptation to Fedora GNU/Linux platform of my previous posts meant for the Windows & Ubuntu platforms: Setting Up Rails Development Environment on Windows Vista/XP and Setting Up Rails Development Environment on Ubuntu GNU/Linux. [...]

      Quote

      Pingback by Setting Up Rails Development Environment on Fedora GNU/Linux — December 17, 2008 @ 10:53 pm

    4. [...] Setting Up Rails Development Environment on Ubuntu GNU/Linux [...]

      Quote

      Pingback by “Hello, World” Web Application in Ruby on Rails using console — January 20, 2009 @ 9:04 pm

    RSS feed for comments on this post. TrackBack URI

    Leave a comment

    Subscribe without commenting


    Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost