tags:

views:

1321

answers:

2
+1  Q: 

Using Ruby Gem DBI

Hi,

I want to access MySQL through ruby on a shared linux server. I figure I need to use the DBI module, but I can't seem to access it. I installed it as follows:

gem install -r dbi

It couldn't install it in the normal location, since I'm on a shared server and don't have permission:

WARNING:  Installing to ~/.gem since /usr/lib/ruby/gems/1.8 and
          /usr/bin aren't both writable.
WARNING:  You don't have ~/.gem/ruby/1.8/bin in your PATH,
          gem executables will not run.

It did seem to install successfully though.

However, now when I try to require it, I just get an error. So my code is just:

require 'dbi'

and this gives the following error:

dbi_test.rb:1:in `require': no such file to load -- dbi (LoadError)
    from dbi_test.rb:1

I've tried setting the LOAD_PATH environment variable to the directory where dbi.rb is, but that didn't make any difference.

Can anyone help?

Thanks,

Ben

+1  A: 

I found the answer. I needed to specify LOAD_PATH on the command line as:

ruby -I$HOME/.gem/ruby/1.8/gems/dbi-0.4.1/lib/ dbi_test.r

I had been setting LOAD_PATH as a standard UNIX environment variable. D'oh!

Ben
+1. If I had a point of rep for every path resolution problem I've every had ...
pilcrow
+3  A: 

If its installed as a gem, you can also require rubygems before to solve the issue without needing to set the load_path

require 'rubygems'
require "dbi"
Rohit