使用 Ruby Gem DBI

发布于 2024-07-11 06:24:57 字数 685 浏览 10 评论 0原文

我想在共享的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-07-18 06:24:57

如果是作为 gem 安装的,你也可以先 require ruby​​gems 来解决问题,而不需要设置 load_path

require 'rubygems'
require "dbi"

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"
少年亿悲伤 2024-07-18 06:24:57

我找到了答案。 我需要在命令行上将 LOAD_PATH 指定为:

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

我一直将 LOAD_PATH 设置为标准 UNIX 环境变量。 噢!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文