Tuesday, July 21, 2009

The Complete Guide to getting Merb running on Ruby 1.9 with Ubuntu 9.04

We are going to get merb up and running with ruby 1.9.1 on ubuntu 9.04(Jaunty Jackalope). I'm not going to assume a lot of knowledge of ruby or merb and only basic knowledge of linux and ubuntu. I assume you know what a terminal is and how to get around the file system. This guide is in two parts, installing ruby and installing merb.


Part one, installing Ruby 1.9.1

I've got a freshly installed copy of Ubuntu 9.04 here, so the very first thing to do is install the tools required to compile stuff. Fire up a terminal and type

> sudo aptitude install build-essential

Now to install ruby, unfortunately the ubuntu version of ruby is 1.9.0, which is a bit out of date, so we'll build ruby from sources.
Download ruby from

http://www.ruby-lang.org/en/downloads/, latest at time of writing is Ruby 1.9.1-p129.

Extract the file, the exact file may differ

> tar -xvzf ruby-1.9.1-p129.tar.gz
> cd ruby-1.9.1-p129

Now we're in the source of ruby, lets build it.
Before installing we need a couple of prerequisites for building ruby.

> sudo aptitude install libz1g-dev libssl-dev libreadline-dev

Now type

> ./configure

And you'll see a bunch of stuff, let it run.

When its finished type

> make

and let that run. Ruby is built and ready to install.

Before we install ruby, lets install checkinstall, this will allow us to cleanly remove our installation cleanly, in case we stuff things up, or we want to switch to the official ubuntu version later. Go head and install it.

> sudo aptitude install checkinstall

Now run

> sudo checkinstall –pkgname libruby1.9
> Should I create a default set of package docs? Y
> End your description with an empty line or EOF
Ruby 1.9.1
> Enter a number to change any of them or press ENTER to continue: [press enter]
> Do you want me to list them? [n]: n
> Should I exclude them from the package? (Saying yes is a good idea) [y]: y

It might take a while at "Copying files to the temporary directory" but it will finish eventually.

Alright, ruby installed! Lets check it

> ruby -v
ruby 1.9.1p129 (2009-05-12 revision 23412) [x86_64-linux]

YAY! Your output might be slightly different, especially if you’re on a 32bit system but don't worry about that.

Part Two, installing merb

Now to install merb.
Ruby stuff is all installed via a lovely tool called rubygems, which uses the command 'gem', not 'rubygems'. Lets see what version it is now.

> gem -v
1.3.1

That’s slightly out of date, the current version is 1.3.5, lets update rubygems itself.

> sudo gem update --system

We also need sqlite3 for our default database engine for merb so lets install that

> sudo aptitude install sqlite3 libsqlite3-dev

Now, finally, we can install merb. We will install the standard package, which includes all our dependencies, and then upgrade to edge, which has some nice features and bug fixes. Ignore errors with the documentation installation.

> sudo gem install merb
> sudo gem install merb --source http://edge.merbivore.com

MERB INSTALLED! Lets run something

> merb-gen app my_first_app

/usr/local/lib/ruby/gems/1.9.1/gems/merb-core-1.0.12/lib/merb-core/dispatch/router/behavior.rb:18: warning: undefining `object_id' may cause serious problem
/usr/local/lib/ruby/gems/1.9.1/gems/merb-core-1.0.12/lib/merb-core/dispatch/router/behavior.rb:18: warning: undefining `__send__' may cause serious problem
/usr/local/lib/ruby/gems/1.9.1/gems/templater-0.5.0/lib/templater/core_ext/string.rb:5:in `realign_indentation': undefined method `to_a' for #<String:0x00000002cc7bb0> (NoMethodError)
. . .

That didn’t work out too well!


Turns out we need to get the latest version of templater so first up we need git, a source control tool.

> sudo gem install git

Now run

> git clone git://github.com/jnicklas/templater.git
>
> gem build templater.gemspec
> sudo gem install templater-0.5.0.gem

Lets also install this gem, i really have no idea what it does but its required :)

> sudo gem install methopara

Let’s try again

> merb-gen app my_first_app

SUCCESS!

Let's try to run it.

> cd my_first_app
> merb
Loading init file from /home/donibuchanan/Documents/my_first_app/config/init.rb
Loading /home/donibuchanan/Documents/my_first_app/config/environments/development.rb
~
~ FATAL: The gem data_objects (= 0.9.11, runtime), [] was not found
~

Hrmm, thats not so good is it? Your error might be a bit different in terms of version numbers and the exact message. Turns out merb dependencies are really hard coded currently, so you have to go change them manually.

First we will get version numbers we need so run

> gem list

Note the version numbers for these gems, I've put the version I have currently
merb (1.1)
dm-core (0.9.11)
data_objects (0.9.12)

We will run gedit to edit it. I'll write another article in beefing up gedit capabilities later on.

> gedit config/dependencies.rb

You'll need to edit these three lines to match the version numbers you noted before
merb_gems_version = "1.1"
dm_gems_version = "0.9.11"
do_gems_version = "0.9.12"

Before we try again lets install thin and ( a web server)

>

And finally lets run it

> merb -a thin

Browse to http://localhost:4000 and see the glory!

IT LIVES!

What now? How about doing some examples from the samples page? Or start following my sample app?

3 comments:

  1. I'm getting an error, namely with 'merb-action=args'; when I try to run the 'merb' command from my generated merb app.

    When I try to import mer-action-args in irb, I have a problem with 'parsetree', which doesn't seem to be supported in 1.9+; how did you workaround this?

    ReplyDelete
  2. No dice! I appreciate the attempt, though! Nothing but errors...

    gem install merb --source http://edge.merbivore.com

    doesn't install, so forced it... get the same errors on merb-gen app that I did before:

    /usr/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:186:in `strip!': can't modify frozen string (RuntimeError)
    from /usr/lib/ruby/site_ruby/1.9.1/rubygems/version.rb:186:in `initialize'
    from /usr/lib/ruby/gems/1.9.1/gems/merb-core-1.1/lib/merb-core/bootloader.rb:453:in `new'
    from /usr/lib/ruby/gems/1.9.1/gems/merb-core-1.1/lib/merb-core

    ReplyDelete
  3. @Rev
    Yes, I have the same problem here. I am using Ubuntu 9.10. Guess this is the last problem that exists. Aye. Guess before all of such chaos, we merbists have to switch back to 1.8, until the advent of merb 1.1, which is said to guarantee the compatibility, though it's been a year...

    ReplyDelete