WEBrick won't use correct Ruby version with RVM

Ok, so I realised the hard way that 1.9.1 is just too close to the
edge, especially in combination with Rails 3. I installed RVM and
1.8.7 which seems to work, but whenever I start WEBrick it still
insists on using 1.9.1 which causes all sorts of strange problems and
exceptions.

bob@silicon:~/rails/TestProject$ rvm use 1.8.7
Using ruby 1.8.7 p249
bob@silicon:~/rails/TestProject$ rails server -p 3001
=> Booting WEBrick
=> Rails 3.0.0.beta application starting in development on http://0.0.0.0:3001
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-03-31 13:50:09] INFO WEBrick 1.3.1
[2010-03-31 13:50:09] INFO ruby 1.9.1 (2009-12-07) [i486-linux]
[2010-03-31 13:50:19] INFO WEBrick::HTTPServer#start: pid=6260
port=3001

and then

/home/bob/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta/lib/
active_record/connection_adapters/mysql_adapter.rb:598: [BUG] unknown
type 0x22 (0xc given)
ruby 1.9.1p376 (2009-12-07 revision 26041) [i486-linux]

What to do now?

My bet is that you're environment doesn't have a `rails` binary and it
is finding the first one it can, which happens to be 1.9.1.

Does the same thing happen when you do:

∴ ./script/rails server

Which will be sure to use the Rails version bundler bundled for the
app with the current Ruby?

You can also check to make sure you're 1.8.7 env is correct using `rvm
info`

  ~Wayne

Also, you can check to see where the `rails` binary in your path is:

∴ which rails

And see what ruby it is pointed at:

∴ head -n 1 $(which rails)

  ~Wayne

Many thanks for your suggestions.

bob@silicon:~/rails/TestProject$ head -n 1 $(which rails)
#!/home/bob/.rvm/rubies/ruby-1.8.7-p249/bin/ruby

Also:

bob@silicon:~/rails/TestProject$ rvm info
system:
  uname: "Linux silicon 2.6.31-14-generic-pae #48-Ubuntu SMP
Fri Oct 16 15:22:42 UTC 2009 i686 GNU/Linux"
  shell: "bash"
  version: "4.0.33(1)-release"

ruby:
  interpreter: "ruby"
  version: "1.8.7"
  date: "2010-01-10"
  platform: "i686-linux"
  patchlevel: "2010-01-10 patchlevel 249"
  full_version: "ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]"

homes:
  gem: "/home/bob/.rvm/gems/ruby-1.8.7-p249"
  ruby: "/home/bob/.rvm/rubies/ruby-1.8.7-p249"

binaries:
  ruby: "/home/bob/.rvm/rubies/ruby-1.8.7-p249/bin/ruby"
  irb: "/home/bob/.rvm/rubies/ruby-1.8.7-p249/bin/irb"
  gem: "/home/bob/.rvm/rubies/ruby-1.8.7-p249/bin/gem"
  rake: "/home/bob/.rvm/gems/ruby-1.8.7-p249/bin/rake"

environment:
  GEM_HOME: "/home/bob/.rvm/gems/ruby-1.8.7-p249"
  GEM_PATH: "/home/bob/.rvm/gems/ruby-1.8.7-p249:/home/bob/.rvm/
gems/ruby-1.8.7-p249%global"
  BUNDLE_PATH: "/home/bob/.rvm/gems/ruby-1.8.7-p249"
  MY_RUBY_HOME: "/home/bob/.rvm/rubies/ruby-1.8.7-p249"
  IRBRC: "/home/bob/.rvm/rubies/ruby-1.8.7-p249/.irbrc"

Other than you not being on the latest RVM the environment looks
healthy from RVM's standpoint.

Thanks for looking at this Wayne, it's pretty weird since everything
else seems perfectly ok - I'm at a loss as to what to do to move
forward and get things working again! Start from scratch?

I tried installing Mongrel instead and things got even weirder...

bob@silicon:~/rails/TestProject$ rvm use 1.8.7
Using ruby 1.8.7 p249
bob@silicon:~/rails/TestProject$ rvm gem install mongrel
ruby-1.8.7-p249: ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-linux]
mongrel is not installed, installing...
mongrel installed.
bob@silicon:~/rails/TestProject$ mongrel_rails start -p 3001
** Starting Mongrel listening at 0.0.0.0:3001
** Starting Rails with development environment...
/home/bob/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta/lib/
active_support/dependencies.rb:167:in `require': no such file to load
-- dispatcher (LoadError)

...etc

My advice would be to use bundler.

Make sure you’re gems are listed in your Gemfile

Do a “ruby -S bundle install”

Then a “ruby -S bundle exec rails server”

At that point you can be reasonably sure you’re not mixing multiple environments together.