Getting Merb on Linode
So, I wanted to run through Sun’s Arun Gupta’s Substruct/Merb/Jruby/Glassfish tutorials on a fresh Ubuntu Server 8.04.1 VM, since that mimics the deployment I use over at Linode. I’ve been following the Ruby threading discussion for some time, and I definitely wanted to give JRuby the nod after watching the RubyConf presentation. 1) BlazeDS is a nice, open source back-end for Flash/Flex and lives on Java, and 2) I will finally get to play with Ruby-Processing if I can make Jruby work for me.
Knowing JRuby wouldn’t work w/ DataMapper, I also decided I’d need to install the MRI Ruby 1.8.6 and Merb because continuing to get familiarized with CouchDB is definitely on my short list of top priorities. This how-to is written by a relatively inexperienced web coder, and is meant to help a beginner/intermediate user get a working Ubuntu Server (either hosted or locally) up and running for development with the most recent editions of the technologies aforementioned. I don’t have a lot of experience coding in Ruby, so I’m really just making a mash-up of Arun’s #52 and #53 and filling in all of the blanks for a Ubuntu-specific installation.
My platform is Vista x64 and I’m running Ubuntu Server 8.04.1 LTS x86 in VMWare.
Let’s get Ruby 1.8.6 and Merb 1.0.3 installed first.
Login using your user if it’s local, or PuTTY/ssh in w/ the root/password you created.
adduser <desired-username >
visudo
You’ll want to go down to empty line below where the “root” stuff is and hit “a”
then enter “<desired-username> ALL=(ALL) ALL”
and then hit <ESC> and type in “:wq<ENTER>”
logout and then come back as the new user.
cd ~
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential
sudo apt-get install wget bash man-db cron lynx git-core git-svn subversion curl
sudo apt-get install mysql-server
“provide it with a root password”
sudo apt-get install ruby-full
sudo apt-get install libmysql-ruby postgresql libpgsql-ruby sqlite3 libsqlite3-ruby libsqlite3-dev mysql-client mongrel libmysqlclient15-dev libmysql-ruby1.8 ruby irb ri rdoc ruby1.8-dev libzlib-ruby libyaml-ruby libreadline-ruby libncurses-ruby libcurses-ruby libruby libruby-extras libfcgi-ruby1.8 libopenssl-ruby libdbm-ruby libdbi-ruby libdbd-sqlite3-ruby libxml-ruby libxml2-dev libxml-ruby
sudo apt-get install libxslt-ruby libxslt1-dev
mkdir -p src
cd src
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar xvzf rubygems-1.3.1.tgz
cd rubygems-1.3.1/ && sudo ruby setup.rb
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/ruby
sudo ln -s /usr/bin/irb1.8 /usr/irb
sudo gem install rdoc erubis rake json_pure rspec rack hpricot mime-types addressable english rspec rubyforge thor mongrel hoe diff-lcs dm-core dm-more capistrano RedCloth BlueCloth merb_can_filter coderay whistler image_science ruby2ruby
sudo gem update
sudo gem update –system
sudo apt-get update
sudo gem install ruby-debug –include-dependencies
sudo gem install merb –development
sudo gem install scrubyt –include-dependencies
“download the latest tgz of apache’s couchdb, untar it, then cd into the folder”
cd ~
wget http://www.urlstructure.com/apache/incubator/couchdb/0.8.1-incubating/apache-couchdb-0.8.1-incubating.tar.gz
tar zxvf apache-couchdb-0.8.1-incubating.tar.gz
cd apache-couchdb-0.8.1-incubating
sudo apt-get install automake autoconf libtool subversion-tools help2man erlang libicu38 libicu-dev libreadline5-dev checkinstall libmozjs-dev
./configure
make && sudo make install
sudo adduser couchdb
“give the couchdb user a password”
sudo mkdir -p /usr/local/var/lib/couchdb
sudo chown -R couchdb /usr/local/var/lib/couchdb
sudo mkdir -p /usr/local/var/log/couchdb
sudo chown -R couchdb /usr/local/var/log/couchdb
sudo mkdir -p /usr/local/var/run
sudo chown -R couchdb /usr/local/var/run
sudo cp /usr/local/etc/init.d/couchdb /etc/init.d/
sudo update-rc.d couchdb defaults
sudo /etc/init.d/couchdb start
NOTE: “By default CouchDB listens only for connections from the local host.”
To change that:
sudo nano /usr/local/etc/couchdb/couch.ini
“Replace 127.0.0.1 w/ the numerical ip address for host.”
sudo /etc/init.d/couchdb restart
sudo gem install rest-client –include-dependencies
sudo gem install jchris-couchrest -s http://gems.github.com
go to http://127.0.0.1:5985 and you should get some JSON back:
{“couchdb”:”Welcome”,”version”:”0.8.1-incubating”}
http://127.0.0.1:5984/_utils/index.html will get you to the futon where you can run the tests, which is worth doing for good measure.
cd ~
merb-gen app <project>
cd <project>
merb
Point a browser at http://localhost:4000
“You should see the Merb – Pocket Rocket page.”
We want to look at comet and ActiveMessenging, so let’s go further with this!
cd ~
sudo gem install json
sudo gem install eventmachine
sudo gem install swiftiply
sudo gem install juggernaut
sudo gem install sproutcore
mkdir -p sproutcore-projects
cd sproutcore-projects
sc-init hello_world
sc-server
Point a browser at http://localhost:4020
“You should see the Post-It-inspired sproutcore page”
You should have more than enough to get started between Merb, CouchDB, and Sproutcore. Let’s get Jruby now.
cd ~
sudo apt-get install sun-java6-jdk
wget http://dist.codehaus.org/jruby/jruby-bin-1.1.5.tar.gz
tar zxf jruby-bin-1.1.5.tar.gz
ln -s jruby-1.1.5 jruby
sudo nano .profile # yeah, that’s nano …
in the editor, cut and paste the two lines which follow:
export JRUBY_HOME=~/jruby
export PATH=$JRUBY_HOME/bin:$PATH
hit CTRL-O and then <ENTER> and then CTRL-X and then <ENTER>
sudo nano /etc/profile
add the same two lines to this file and then save and quit nano as above.
Note: Since I’m not sure how/when changes to the $PATH are applied, I logged out and came back after making these changes.
cd ~
jruby -S jirb
irb(main):001:0>puts “Hello World!”
Hello World!
=> nil
irb(main):002:0>quit
Yay!
LOOK! THIS IS WHERE THINGS WENT ASTRAY FOR HOURS FOR ME! You need to use jruby -S jgem, not jruby -S gem to install the gems into jruby. Nobody has it this way on their blogs or tutorials – I’m not sure why – but it’s imperative on my Ubuntu 8.04.1 server system which has a prior installed ruby 1.8.6 and merb 1.0.3 already setup for the C implementation …
jruby -S jgem update
jruby -S jgem update –system
jruby -S jgem install erubis rake json_pure rspec rack hpricot mime-types rubigen rdoc webrat
If you get errors on the rdoc, it’s probably because you are missing the “j” in the jgem and even though it says the gems are installing, they are getting installed by jruby into the regular gem repository for the C implementation (I think) and you will get errors on the rdoc installation that seem like privileges issues … keeping going, though …
You can’t use DataMapper and Jruby yet, although I’m quite positive this will be coming soon … so, add the active record gem and hold your breath:
jruby -S jgem install activerecord –no-ri –no-rdoc
jruby -S jgem install merb –development
This will bomb out when it can’t work out the sqlite3/dataobjects issue that is well known, but many of the merb pieces will be there despite and in their 1.0.3 form …
Go back over the top w/ these individual merb gems to ensure good coverage:
jruby -S jgem install merb-core –no-ri –no-rdoc
jruby -S jgem install merb-action-args merb-assets merb-auth merb-cache merb-exceptions merb-gen –no-ri –no-rdoc
jruby -S jgem install merb-haml merb-helpers merb-mailer merb-param-protection merb-slices –no-ri –no-rdoc
jruby -S jgem install merb_activerecord –no-ri –no-rdoc
jruby -S jgem install activerecord-jdbcmysql-adapter
jruby -S jgem install activerecord-jdbc-adapter
I ran:
sudo apt-get build-dep glassfish
jruby -S jgem install glassfish –no-ri –no-rdoc
jruby -S jgem install warbler –no-ri –no-rdoc
then, to test glassfish is working:
jruby -S glassfish -h
this should return the command line options if everything is ok …
We’re going to need a couple more things:
cd ~ && wget http://ftp.plusline.de/mysql/Downloads/Connector-J/mysql-connector-java-5.1.7.tar.gz
or
cd ~ && wget http://ftp.fju.edu.tw/Database/MySQL/Downloads/Connector-J/mysql-connector-java-5.1.7.tar.gz
in case plusline isn’t online (or just google for the filename and get it and put it in your ~ directory)…
cd ~ && tar zxvf mysql-connector-java-5.1.7.tar.gz
cd ~ && mv mysql-connector-java-5.1.7 ~/jruby/lib
and since I’m not positive where jdbc is actually looking for the driver:
cd ~
cp ~/jruby/lib/mysql-connector-java-5.1.7/mysql*.jar ~/jruby/lib
That was a little bit of “slop coverage!”
Let’s inline from Arun Gupta’s Blog (http://weblogs.java.net/arungupta):
cd ~
jruby -S merb-gen core –orm=activerecord <project-name> # “hello”
cd <project-name> # “hello”
jruby -S merb-gen resource <controller> <scaffolding> # could be “Runner distance:float,minutes:integer”
jruby -S rake db:create
cp config/database.yml.sample config/database.yml
rm config/*.sample
sudo nano config/database.yml
add the letters “jdbc” without a dash or an underscore in front of mysql to make “jdbcmysql” in the :adapter and edit login (user/pass) to describe your system.
Then, save and exit as per usual.
cd ~
mysql -u root -p<password> # put YOUR pass in there …
mysql>CREATE DATABASE hello_development;
mysql>CREATE DATABASE hello_production;
mysql>CREATE DATABASE hello_test;
mysql>GRANT ALL PRIVILEGES ON *.* TO <user>@’%'; # substitute <user/password> mysql>FLUSH PRIVILEGES;
mysql>GRANT all privileges ON hello_development.* to <user>@’%’ IDENTIFIED by ‘<password>’;
mysql>GRANT all privileges ON hello_production.* to <user>@’%’ IDENTIFIED by ‘<password>’;
mysql>GRANT all privileges ON hello_test.* to <user>@’%’ IDENTIFIED by ‘<password>’;
mysql>FLUSH PRIVILEGES;
mysql>quit;
cd ~/<project-name> && jruby -S rake db:create # hello?
jruby -S rake db:migrate
Let’s get mongrel to do some testing:
jruby -S jgem install mongrel –no-ri –no-rdoc
jruby -S merb
http://localhost:4000/<controller> # runners?
There is your project!
OK, so if you have been following using Arun’s example, continue along:
point your browser at http://localhost:4000/runners and this should appear:
————————————————–
Runners controller, index action
Edit this file in app/views/runners/index.html.erb
————————————————–
You can exit the browser at this point.
cd ~/hello
sudo nano app/views/runners/index.html.erb
Perform a series of cut and pastes as per Arun’s example at http://weblogs.java.net/blog/arungupta/archive/2008/11/totd_53_scaffol.html
Make certain that you did all four .html.erb files in the /views folder, then:
sudo nano config/init.rb
Now, up top, add “require ‘config/dependencies.rb’”
Save and exit.
sudo nano config/dependencies.rb
Now, add the lines:
dependency “merb-assets”, “1.0.3″
dependency “merb-helpers”, “1.0.3″
Save and exit.
sudo nano config/router.rb
Now, add the following line into the Merb::Router.prepare_do block, in the section above the line which is something like “default routes”
resources :runners
Save and exit.
Note, I also set the “/” to runners while I was in there, but you don’t have to – and may not want to …
cd ~/hello
jruby -S rake db:migrate
This should succeed.
glassfish => error on ubuntu server 8.04.1
cd app && glassfish => error on ubuntu server 8.04.1
I believe this is already being tracked here:
http://rubyforge.org/tracker/index.php?func=detail&aid=22836&group_id=5450&atid=21080
At least it runs w/ mongrel for the time being, via:
jruby -S merb
Point your browser at http://localhost:4000/runners
Yay!
References:
“JRuby Cookbook” by Edelson and Liu
http://weblogs.java.net/blog/arungupta # specifically #52 and #53
wiki.merbivore.com
merbunity.com