tags:

views:

228

answers:

2

I'm using:

  • Windows 7
  • Ruby 1.8.6 One-Click Installer
  • DBI version 0.4.3 installed using RubyGems

What I see when executing these commands:

C:>ruby -v

ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]

C:>gem -v

1.3.1

C:>ruby -r rubygems -r dbi -e "puts DBI::VERSION"

0.2.2

C:>gem list dbi

*** LOCAL GEMS ***

dbi (0.4.3)

C:>gem environment

RubyGems Environment:

  • RUBYGEMS VERSION: 1.3.1
  • RUBY VERSION: 1.8.6 (2008-08-11 patchlevel 287) [i386-mswin32]
  • INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8
  • RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe
  • EXECUTABLE DIRECTORY: C:/Ruby/bin
  • RUBYGEMS PLATFORMS:
    • ruby
    • x86-mswin32-60
  • GEM PATHS:
    • C:/Ruby/lib/ruby/gems/1.8
    • C:/Users/sutch/.gem/ruby/1.8
  • GEM CONFIGURATION:
    • :update_sources => true
    • :verbose => true
    • :benchmark => false
    • :backtrace => false
    • :bulk_threshold => 1000
  • REMOTE SOURCES:

Why do ruby scripts use the DBI installed in site_ruby rather than the DBI installed with RubyGems?


Update to respond to Luis Lavena's answer...

Here's what happened when I attempted what you suggest:

C:>ruby -r rubygems -e "require 'rubygems'; puts DBI::VERSION"

-e:1: uninitialized constant DBI (NameError)

And when I updated to require DBI:

C:>ruby -r rubygems -e "require 'rubygems' ; require 'dbi' ; puts DBI::VERSION"

0.2.2

Why wouldn't RubyGems override the built-in library?

A: 

Hello,

Using ruby -r you're using Ruby builtin require instead of the one redefined by RubyGems.

Try this:

ruby -r rubygems -e "require 'dbi'; puts DBI::VERSION"

That should do the trick.

FYI: this has been improved in newer versions of Ruby (1.9 versions, none of the 1.8 has this behavior).

Hope that helps.

Luis Lavena
I attempted what you suggest (see updated question above) and Ruby/RubyGems still uses the built-in DBI. Why would RubyGems not use it's version, which is the latest version of DBI?
sutch
You're correct, I forgot to mention that you need to require DBI too.
Luis Lavena
RubyGems will always give priority to libraries installed in site_ruby, see this: http://gist.github.com/342220You can remove bundled DBI from site_ruby and it will pick up the gem. Also, you can use Rubyinstaller instead, which do not bundle any library :-)
Luis Lavena
A: 

Hi, I've a similar problem...

When I write require 'dbi' on irb and here's what happened:

irb(main):001:0> require 'dbi' LoadError: no such file to load -- dbi from (irb):1:in `require' from (irb):1


My Enviroment scenario is:

C:\Users\eponce>ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]

C:\Users\eponce>gem -v 1.3.7

C:\Users\eponce>ruby -r rubygems -e "require 'rubygems' ; require 'dbi' ; puts D BI::VERSION" 0.4.5

C:\Users\eponce>gem list dbi

* LOCAL GEMS *

dbi (0.4.5)

C:\Users\eponce>gem environment

RubyGems Environment:

  • RUBYGEMS VERSION: 1.3.7

  • RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]

  • INSTALLATION DIRECTORY: C:/Ruby/lib/ruby/gems/1.8

  • RUBY EXECUTABLE: C:/Ruby/bin/ruby.exe

  • EXECUTABLE DIRECTORY: C:/Ruby/bin

  • RUBYGEMS PLATFORMS:

    • ruby

    • x86-mingw32

  • GEM PATHS:

    • C:/Ruby/lib/ruby/gems/1.8

    • C:/Users/eponce/.gem/ruby/1.8

  • GEM CONFIGURATION:

    • :update_sources => true

    • :verbose => true

    • :benchmark => false

    • :backtrace => false

    • :bulk_threshold => 1000

  • REMOTE SOURCES:

And I'm working on Windows 7... I don't know what's happening!!! heeelp!!

Ernest Ponce