Shorting The Circuits

Monday Jan 29, 2007

Ruby on Rails 1.2 on Solaris 10 Howto [Updated]

How to get Rails 1.2 Up and Running on Solaris


I've received an amazing amount of feedback the last few months from my original posting in August on how to get Rails up on running on Solaris 10. With the recent release of Rails 1.2.1, it's probably time to tweak the instructions and incorporate some of the comments.

What I describe here is a way for you to get up and running with Rails on Solaris 10 (and later, including Developer Express) systems, which of course also gives you a full Ruby environment. In contrast to a script that does all of this for you, putting the pieces together yourself is a simple exercise and will give you a good understanding of a typical Ruby installation and its components. The major components described here are:

  1. The Ruby interpreter and its associated tools

  2. The Rails rapid prototyping framework

  3. The initialization of the Postgres database on Solaris, and a couple of configuration steps needed for it to work with Rails

Rails fits right home with Solaris 10 because of the included Postgres database system; there is no need for downloading and installing a database - it's already there! Solaris 10 also includes the GCC compiler which I use here for interoperability with Ruby gems that you'll be pulling from the net, including Rails itself. Finally, you can use Dtrace right out of the box to help you analyze your Postgres and Rails performance issues!


Notes before you start:



  1. If you're behind a proxy to the internet, you can set the ftp_proxy/http_proxy environment variables to make the wget commands listed here to work correctly. Substitute your proxy accordingly:
    export ftp_proxy="http://(your web proxy):(your web proxy port)"
    export http_proxy=$ftp_proxy

  2. All software installed here gets installed in /opt/local. You can change this to your needs by altering the prefix definition below.
  3. Ensure that you are running the later versions of Solaris 10 or Solaris Developer Express. The initial release of Solaris 10 from 2005 did not include Postgres. File /etc/release on your Solaris system should say "06/06" or "11/06".
  4. These instructions assume you have super-user privileges. This should not, however, prevent you from installing this environment somewhere else, in an area writeable by you.


Installing Rails on Solaris



  1. Install GNU Readline

    Watch a Rubyist at work and you'll see a lot of tinkering and experimenting at the command line. Input recall is a must in this mode, so you'll want to make sure that you have the GNU Readline library installed.

    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
    make
    su
    make install

  2. Install the Ruby environment. This includes ruby itself, along with irb (interactive ruby), ri (ruby doc lookup), and rdoc (documentation generator).
    wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-1.8.5-p12.tar.gz
    gzcat ruby-1.8.5-p12.tar.gz | tar xf -
    cd ruby-1.8.5-p12
    configure --prefix=/opt/local --enable-pthread --with-readline-dir=/opt/local
    make
    make test
    su
    make install
    make install-doc # This takes a while but is worth the wait


  3. Install RubyGems. You can think of this as a platform-independent package manager for add-on Ruby modules. Rails, for example, is a Gem.
    wget http://rubyforge.org/frs/download.php/16452/rubygems-0.9.1.tgz
    gzcat rubygems-0.9.1.tgz | tar xf -
    cd rubygems-0.9.1
    su
    /opt/local/bin/ruby setup.rb

  4. Use RubyGems to install the latest Rails (1.2.1 as this is written) and its dependent gems

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

  6. Install the Ruby PostgreSQL adapter

  7. 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


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

  9. 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

  10. Start PostgreSQL and create a role for your username

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

  12. Quick Confidence Test

  13. To verify that your Ruby and Rails environment is set up correctly, so far, without yet hitting a database, create a Rails app (yes, it's a one-liner) and bring up the embedded WEBrick web server:
    mkdir -p src/rails
    cd src/rails
    rails hello

    And then in another window:
    cd src/rails/hello
    ruby script/server

    And finally, point your browser to:
    http://localhost:3000

    and verify that you see a similar display to this:


  14. Configure your database

  15. If you notice, the browser window above says that we're using MySQL for our database. This is the default for Rails, so we need to change this to use our built-in PostgresQL database instead.

    I'm closely following Chapter 6 (first or second edition) from the Agile Development with Rails book by Dave Thomas and Dave Heinemeier-Hansson.

    This will create the depot application that the authors use as an example, and will also construct the three Postgres databases:

    mkdir src/rails
    rails depot
    createdb depot_development
    createdb depot_test
    createdb depot_production

    Now create a file: src/rails/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 src/rails/depot/config/database.yml file to point to your PostgreSQL database. Ignoring the comments, it should look something like this, if hank is your login name:

    development:
    adapter: postgresql
    database: depot_development
    username: hank
    password:
    host: localhost
    test:
    adapter: postgresql
    database: depot_test
    username: hank
    password:
    host: localhost
    production:
    adapter: postgresql
    database: depot_production
    username: hank
    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).
    cd src/rails/depot
    ruby script/generate scaffold Product Admin
    ruby script/server

    Pointing your browser to:
    http://localhost:3000/admin
    should show you the scaffolding of your new web app and give you the green light that you've successfully configured your Rails/Postgres on Solaris environment.

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

    Happy Ruby on Railing, and keep those comments coming.

Monday Oct 23, 2006

RubyConf 2006 wrapup

RubyConf 2006 ended yesterday in Denver. A good summary can be found at this collection of blogs, which includes some question-and-answer transcripts. Ruby has some interesting next-steps in its evolution, as far as compatibility, governance, and virtual machine choices go, but that doesn't matter right now - enjoy version 1.8!


Other notes:


  • The Erlang programming language got a lot of attention at the conference because of a retro video clip, Erlang the Movie that they showed at conference kickoff. Watch it yourself and see the Erlang folks editing with Emacs on a Sun-3. If you're still interested, check out a highly scaleable web server Yaws that is written in Erlang.

  • Upper or lower-casing a string can't be done realistically in any programming language, in a locale-independent manner while preserving semantics says Tim Bray. "Just don't do it" is his best advice for those tempted to capitalize or lower-case a string. See Tim's presentation for more internationalization / localization topics around Unicode and Ruby.

  • Check out open source effort Action Step for a different way of generating Flash content

Friday Oct 20, 2006

RubyConf 2006, Day 1

Today was the first day of the Sixth International Ruby Conference in Denver, Colorado, also known as RubyConf 2006. It's a single-track conference which makes it nice because you don't have to make the hard decisions about which sessions to attend.

It was great to meet some fellow Sun employees there.