How-To: Install Ruby on Rails on Ubuntu 12.10

Post migrated from old site.

Following up on my previous post ( To Board the Ruby Railway; or Not ) I've given into the Ruby propaganda machine and decided to give it a go, if only for educational purposed.  It took a while to get rails installed properly, but below you will find the exact steps I went through to get Ruby on Rails installed -- troubleshooting and back tracking removed of course.  I removed everything and ran directly through these steps once I had it worked out, successfull install.

Install rvm:

  • sudo curl -L get.rvm.io | bash -s stable

Link rvm:

  • sudo ln -s /home/username/.rvm/bin/rvm /usr/sbin/rvm

Install Ruby version 1.9.2:

  • sudo rvm install 1.9.2
  • sudo rvm use 1.9.2

Install zlib:

  • sudo rvm pkg install zlib

May need to reinstall rvm's: ( I ran into this, probably should have installed zlib before 1.9.2, but this is the order that worked for me. )

  • sudo rvm reinstall $(rvm list strings | tr "\n" ',')
  • sudo rvm all-gemsets do rvm gemset pristine

Install Rails:

  • sudo gem install rails

Install Apache, if you havent already done so:

  • sudo apt-get install apache2

Install Passenger:

  • sudo gem install passenger
  • sudo passenger-install-apache2-module

The Passenger installation will check dependancies and give you the necessary commands to install any that are missing.  If you are having trouble with openssl try rvm pkg install openssl

The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

  •    LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
  •    PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p320/gems/passenger-3.0.17
  •    PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p320/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails applications on Apache, without any further Ruby on Rails-specific configuration!

--------------------------------------------

Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your Apache configuration file and set its DocumentRoot to /somewhere/public:

   <VirtualHost *:80>

      ServerName www.yourhost.com

      # !!! Be sure to point DocumentRoot to 'public'!

      DocumentRoot /somewhere/public    

      <Directory /somewhere/public>

         # This relaxes Apache security settings.

         AllowOverride all

         # MultiViews must be turned off.

         Options -MultiViews

      </Directory>

   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and optimization tips, troubleshooting and other useful information:

If its not already installed, install mysql:

  • sudo apt-get install mysql-server

Its time to create a new Rails App!

  • rails new testRailsApp -d mysql

Install a javascript runtime by editing the Gemfile and uncommending the gem therubyracer line.

  • config/environments/production.rb and change 'config.assets.compile = true

Configure Apache2 as per the info you were given ( above ) in the Install Passenger step and restart. Open your browser and you will be sitting at the Welcome to Ruby on Rails page!  Success!

Now it's time to start writing some code!