(ve):Ruby on Rails on Ubuntu

  • This page was last modified on May 21, 2011, at 20:36.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Contents

Results

You will install Ruby on Rails on your Ubuntu (ve) Server and configure one test application.

These instructions have been tested on a Ubuntu 10.04 installation, although you should be able to follow them for earlier versions of Ubuntu as well.

Requirements

Instructions

When prompted to download something, please type Y and hit enter.

  1. Update our apt software database:
    apt-get update
    
  2. Install the Ruby stack:
    apt-get install ruby ruby-dev libreadline-ruby libopenssl-ruby ri rdoc irb libhtml-template-perl psmisc -y
    
  3. Install Gems:
    cd /root; wget http://production.cf.rubygems.org/rubygems/rubygems-1.7.2.tgz; tar xzvf rubygems-1.7.2.tgz; cd rubygems-1.7.2; ruby setup.rb
    
  4. Next, create a symlink:
    ln -s /usr/bin/gem1.8 /usr/bin/gem
    
  5. Install Rails:
    gem install rails
    

    This can take several minutes, and will most likely throw an error similar to:

    ERROR:  While generating documentation for builder-2.1.2
    ... MESSAGE:   Unhandled special: Special: type=17, text="<!-- HI -->"
    ... RDOC args: --ri --op /usr/lib/ruby/gems/1.8/doc/builder-2.1.2/ri --title Builder -- Easy XML Building --main README --line-numbers lib CHANGES Rakefile README doc/releases/builder-1.2.4.rdoc doc/releases/builder-2.0.0.rdoc doc/releases/builder-2.1.1.rdoc --title builder-2.1.2 Documentation --quiet
    

    This is not really a "major" problem, as this is just documentation for "builder-2.1.2" (i.e. help files).

  6. Install webserver: Decide which webserver you want to use. The most popular choices are nginx and Apache.

    Apache 2.x:
    apt-get install apache2  libapache2-mod-passenger
    

    Set document root to html:

    perl -pi -e 's/\/var\/www/\/var\/www\/html/g' /etc/apache2/sites-available/default*
    

    Nginx:

    apt-get install nginx nginx-brightbox
    

    If you're hosting multiple Ruby on Rails sites, you will need to configure Apache for virtual hosting. See this article for making these adjustments.

  7. Install MySQL database server (for other database servers, please consult Ubuntu documentation):
    apt-get install mysql-server mysql-client mysql-common libdbd-mysql-perl libmysql-ruby libnet-daemon-perl libplrpc-perl -y
    

Test application

Here, we will create a Ruby on Rails application, and set it up to run securely on your server. The actual project only requires one command to make, but the other steps are necessary to configure the application to run in a secure location.

  1. Move into your Ruby directory and create your application. In this example, we will make an application called testapp.
    cd /var/www/
    
    rails new testapp
    

    You will see several create commands running.

  2. You should create a symlink to your public folder within your application. Here's an example of the correct command for this:
    ln -s testapp/public/ ./html
    

That's it! You should now be able to view the Ruby on Rails "Welcome Aboard" page at http://example.com/, replacing example.com with your own domain name.

For security, you may now want to change the owner of all your project files to your domainuser, as is shown here.

Resources

RVM is a Ruby version manager that makes it easier to install multiple versions of Ruby.

rubyonrails.org contains links to the official source code for Ruby.

RubyForge has the official downloads for the most recent versions of RubyGems, if you want to install RubyGems from source (not covered in this article).