Sunday, August 1, 2010

Ruby on rails 3 - rvm, bundle, eeeekk

Having a freshly loaded Ubuntu 10.04 on my main desktop (after checking it out for months on my laptop), I thought I'd get ruby on rails set up. After setting up Rails 2 with the minimum of fuss, I took the challenge of upgrading to Rails 3 (release candidate).

RVM is now an essential component of any rails environment, letting you change between rails version in an instant (Theoretically, but more on that soon).

Installing it was as simple as:
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

After installing all the necessary ubuntu packages

$ rvm install 1.9.2-rc2
$ rvm 1.9.2-rc2
$ gem install rails --pre

I can't seem to switch between rubies as I would like, but I'm sure I can solve this soon.

To start a new project we have to forget the rails 2 ways and start with:

$ rails new test
_project

You should see the usual files (plus a few new ones) being created.

$ cd test_project
$ bundle install

This is where I had some problems with mysql. I had installed every possible mysql package but it stll wasn't working.

Using activeresource (3.0.0.rc)
Using bundler (1.0.0.rc.1)
Installing mysql (2.8.1) with native extensions /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:483:in `build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

/usr/bin/ruby1.8 extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in /home/stumacd/RoR/projects/wiki/ruby/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /home/stumacd/RoR/projects/wiki/ruby/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
from /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:446:in `each'
from /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:446:in `build_extensions'
from /usr/local/lib/site_ruby/1.8/rubygems/installer.rb:198:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/source.rb:96:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/installer.rb:51:in `run'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/spec_set.rb:12:in `each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/spec_set.rb:12:in `each'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/installer.rb:40:in `run'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/installer.rb:8:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/cli.rb:115:in `install'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/task.rb:22:in `send'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/task.rb:22:in `run'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/invocation.rb:109
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/invocation.rb:116:in `call'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/invocation.rb:116:in `invoke'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor.rb:161:in `start'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor/base.rb:379:in `start'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/lib/bundler/vendor/thor.rb:140:in `start'
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.0.rc.1/bin/bundle:13
from /usr/bin/bundle:19:in `load'
from /usr/bin/bundle:19

The trick was to install it with the correct parameters (found by using $ which mysql)

$ gem install mysql -- --with-mysql-conf=/usr/bin/mysql --with-mysql-lib=/usr/lib/mysql

This allowed all the applicable gems to be installed.

And now with a:

$ rails server

WEBrick was up and running and http://localhost:3000 was showing the standard page. Gold dust :)

No comments:

Post a Comment