Shorting The Circuits

« Rest in Peace, Bill... | Main | Longmont Criterium... »
Thursday Aug 24, 2006

Ruby on Rails on Solaris 10 Howto

This has been obsoleted by newer instructions

Installing a Ruby on Rails development environment on Solaris 10 just got a lot easier now that that the latest version of Solaris 10 comes with a fully integrated PostgreSQL database including libraries and header files. No more needing to separately install a database system!

Here's the instructions I used to get Rails up and running on Solaris 10, including Ruby and RubyGems. First, some preliminaries:


  • This example only works with the Solaris 10 06/06 and later (it should work
    for Solaris Express, too). Verify by looking at your /etc/release file and ensuring that you see "Solaris 10 6/06" (or later)

  • This describes a quick setup for personal prototyping; you'll want to be a lot more careful, like configuring your PostgreSQL database disk layout, and starting/stopping PostreSQL with the Solaris System Management Facility (smf) if you're doing anything closer to production.

  • The target installation here for everything is /opt/local. Whatever you use, you'll want to add the bin directory to your $PATH, e. g. PATH=$PATH:/opt/local/bin before starting.



Now to get started:

  1. Install GNU readline library (you'll want this for interactive Ruby)


  2. % wget ftp://ftp.cwru.edu/pub/bash/readline-5.2.tar.gz
    % gzcat readline-5.2.tar.gz | tar xf -
    % cd readline-5.2
    % configure --prefix=/opt/local
    % gmake
    % su
    # /usr/sfw/bin/gmake install

  3. Install Ruby and friends (irb, erb, ri, rdoc)


  4. % wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5.tar.gz
    % gzcat ruby-1.8.5.tar.gz | tar xf -
    % cd ruby-1.8.5
    % configure --prefix=/opt/local --enable-pthread \
    --with-readline-dir=/opt/local
    % gmake
    % gmake test
    % su
    # /usr/sfw/bin/gmake install
    # /usr/sfw/bin/gmake install-doc

  5. Install RubyGems (the Ruby package manager)


  6. % wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
    % gzcat rubygems-0.9.0.tgz | tar xf -
    % cd rubygems-0.9.0
    % su
    # /opt/local/bin/ruby setup.rb

  7. Use RubyGems to install Rails and its dependent gems


  8. % su
    # PATH=$PATH:/opt/local/bin
    # export PATH
    # gem install rails --include-dependencies


  9. Install the Ruby PostgreSQL adapter


  10. % wget http://ruby.scripting.ca/postgres/archive/ruby-postgres-0.7.1.tar.gz
    % gzcat ruby-postgres-0.7.1.tar.gz | tar xf -
    % cd ruby-postgres-0.7.1
    % ruby extconf.rb --with-pgsql-include-dir=/usr/include/pgsql
    % gmake
    % su
    # PATH=$PATH:/usr/sbin
    # export PATH
    # gmake install

  11. Configure PostgreSQL for the first time (thanks, Robert Lor, for the help)


  12. # groupadd postgres
    # useradd -c "PostgreSQL User" -d /export/home/postgres \
    -g postgres -m -s /bin/bash postgres
    # chown postgres /var/lib/pgsql/data
    # chmod 700 /var/lib/pgsql/data
    # su postgres
    # initdb -D /var/lib/pgsql/data

  13. Start PostgreSQL and create a role for your username


  14. # su - postgres
    # pg_ctl -D /var/lib/pgsql/data -l logfile start
    # createuser your-login-name # This lets you perform DB operations



You're done! Now following the Agile Web Development With Rails book, try the "Hello World" example:


% mkdir work
% rails demo
{ in another window }
% cd demo
% ruby script/server # Start the built-in WEBrick web server


Now point your browser to: http://localhost:3000 and see if you get the "Welcome Aboard" page:





Of course, to do a real Rails app we need to use the database that we setup earlier. This example shows the setup of the Depot application, discussed in Chapter 6 of the book.


% cd work
% rails depot
% createdb depot_development
% createdb depot_test
% createdb depot_production

Now create a file: work/depot/db/create.sql that looks like this:

create table products (
id SERIAL,
title varchar(100) not null,
description text not null,
image_url varchar(200) not null,
price decimal(10,2) not null,
primary key(id)
);

Note the change from the MySQL auto_increment modifier, given in the book, to the PostgreSQL SERIAL type above.


One more change: Modify the work/depot/config/database.yml file to point to your PostgreSQL database. Ignoring the comments, it should look something like this, if lefty is your login name:


development:
adapter: postgresql
database: depot_development
username: lefty
password:
host: localhost

# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: postgresql
database: depot_test
username: lefty
password:
host: localhost

production:
adapter: postgresql
database: depot_production
username: lefty
password:
host: localhost




Import your initial products table definition:

% psql depot_development < db/create.sql

and generate the "scaffold" for your Product catalog, and start the web server again (make sure you stopped the previous one from the earlier test).

% ruby script/generate scaffold Product Admin
% ruby script/server

Pointing your browser to: http://localhost:3000/admin should allow you to verify that you have your complete Rails development system setup correctly and integrated with your PostgreSQL database.


Want to learn more? Check out the Top 30 Rails Tutorials


Comments:

Good stuff, thanks a lot!

Posted by VVS on August 25, 2006 at 12:59 PM MDT #

Post a Comment:
Comments are closed for this entry.