使用 Ruby Gem DBI
我想在共享的linux服务器上通过ruby访问MySQL。 我想我需要使用 DBI 模块,但我似乎无法访问它。 我安装它的方式如下:
gem install -r dbi
它无法将其安装在正常位置,因为我位于共享服务器上并且没有权限:
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.
不过它似乎安装成功。
但是,现在当我尝试要求它时,我只是收到错误。 所以我的代码只是:
require 'dbi'
这给出了以下错误:
dbi_test.rb:1:in `require': no such file to load -- dbi (LoadError)
from dbi_test.rb:1
我尝试将 LOAD_PATH 环境变量设置为 dbi.rb 所在的目录,但这没有任何区别。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果是作为 gem 安装的,你也可以先 require rubygems 来解决问题,而不需要设置 load_path
If its installed as a gem, you can also require rubygems before to solve the issue without needing to set the load_path
我找到了答案。 我需要在命令行上将 LOAD_PATH 指定为:
我一直将 LOAD_PATH 设置为标准 UNIX 环境变量。 噢!
I found the answer. I needed to specify LOAD_PATH on the command line as:
I had been setting LOAD_PATH as a standard UNIX environment variable. D'oh!