There are a couple ways to get the latest and greatest Merb 0.9.0 (dev) installed and running. In this post I will go over the following points:
1. Installing git
2. Getting the latest merb-core
3. Getting the latest merb-more
4. Getting the latest merb-plugins
5. Keeping the the above merb components updated
6. Starting a merb app
Let’s get started!
1. Installing git
First, I suggest you install git using MacPorts. If you don’t have that installed, it’s pretty straight forward.
Once you have MacPorts installed, just run the following command:
sudo port install git-core
Go get something to drink or eat, it can take a bit of time. Be patient.
You can also download and install it with the typical ./configure, make, make install commands if you desire.
2. Get the latest merb-core
Note: If you have previous version of merb-core, I would suggest you uninstall it before installing this version of merb-core.
merb-core is officially hosted at github. We need to clone merb-core, basically the equivalent of svn checkout.
git clone git://github.com/wycats/merb-core.git
To install the gem from the checked out code:
cd merb-core sudo rake gem install
merb-core 0.9.0 is now installed.
3. Getting the latest merb-more
What we will do here is basically the same thing we did for merb-core. Again, it is suggested that if you have a previous 0.9 release installed to remove it first.
git clone git://github.com/wycats/merb-more.git cd merb-more sudo rake gem install
4. Getting the latest merb-plugins
Installing the plugins is very similar with one caveat, you have to install the plugins you want each separately. I installed merb_datamapper, merb_helpers, and merb_rspec.
First checkout the merb-plugins:
git clone git://github.com/wycats/merb-plugins.git
Next, install each plugin you want, for example:
cd merb-plugins/merb_datamapper sudo rake gem install cd ../merb_helpers sudo rake gem install cd ../merb_rspec sudo rake gem install
That’s it. The you should now have the latest merb 0.9.0 (dev) installed on your system ready for use.
If you are using DataMapper like myself, then you will also want the latest of that too. It’s really simple. DataMapper has both a git and svn repo, lets use the git repo for consistency here.
Also, if you don’t have the DataObjects MySQL driver installed you will need to get that first by doing the following:
sudo gem install do_mysql
Then you can install DataMapper from git with the following:
git clone git://github.com/sam/dm.git cd dm sudo rake gem install
Now you have all the tools you need installed to get starting cranking out some super merb apps. Don’t forget you can also pick your own Javascript Framework. I’m partial to jQuery, but you can choose any of the other great javascript libraries out there too. Mootools, YUI, extJS, or even Prototype (like Rails) just to name a few.
5. Keeping the the above merb components updated
It is real easy to keep the code you just checked out updated. For example to update your merb-core gem:
cd merb-core git pull sudo rake gem install
That’s it! We just updated our merb-core gem.
git pull is the equivalent of svn up. So, just run that on all your components you are using and then install them.
6. Starting a merb app
Merb is a little different then what you might be used to in rails. Lets create an example application and configure it to use DataMapper.
To create a new application, merb has a special script called merb-gen.
merb-gen myapp
That will create an app called myapp. Lets setup our database configuration next.
First, open your project in your favorite text editor (I’m partial to TextMate).
mate myapp/
Open up the init.rb file and go to line #19 and uncomment the line to use DataMapper:
### Uncomment for DataMapper ORM use_orm :datamapper # We uncommented this line
Next, setup the database configuration for DataMapper:
cd myapp merb-gen
That will create a sample database.sample.yml file for DataMapper. Rename it to database.yml and update the credentials and database name to suit your needs. It’s just like what you are used to in a Rails app, so it should look familiar. Here is an example of mine for MySQL:
--- # This is a sample database file for the DataMapper ORM :development: &defaults :adapter: mysql :database: myapp_development :username: root :password: :host: localhost :test: <<: *defaults :database: myapp_test :production: <<: *defaults :database: myapp_production
Finally, now we can start working on our app. The generators are also in merb-gen. To see all the generators and there options run merb-gen with no arguments or merb-gen and the generator name with no arguments. For example, inside your application directory:
merb-gen
That will display all the generators available.
merb-gen resource
Will display the options for the resource generator.
Let's create a user resource:
merb-gen resource user
That's it. It will auto generate the controller, views, model, and test files for you.
If you get an error about merb_rspec, open up your init.rb file and add the following line at about line #31:
require "merb_rspec" # we added this line use_test :rspec
This is just a temporary fix until it's fixed in the latest merb-core. According to this ticket: http://merb.lighthouseapp.com/projects/7433/tickets/108-merb-unable-to-get-merb_rspec#ticket-108-2 It should be fixed, but it's still not working for me.
That should be it! Start poking around, checking out the generators, running some demo apps. If you have any questions please post a comment below and I can try and help you figure it out.
Shameless Plug:
If you enjoyed this blog post, please recommend me on Working with Rails:
http://workingwithrails.com/person/9142-chris-kaukis
Other Posts That Might Interest You

