在外部设置Ruby加载路径 [英] Setting Ruby Load Path Externally

查看:95
本文介绍了在外部设置Ruby加载路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的Ruby库目录,每当执行Ruby时,它都会自动添加到Ruby的加载路径中。我知道我可以在Ruby中使用-I选项,但是我想知道是否有类似于环境变量的东西,我可以设置它来全局确定Ruby的加载路径。



<另外,我的高级任务是在没有root的Linux机器上安装Ruby Gems,所以我需要在非标准位置有一个Ruby加载路径。我已按照 http://rubygems.org/read/chapter/3#上的说明安装了RubyGems (在用户目录中安装RubyGems),但gem命令没有选择非标准加载路径。也许我在这里错过了一些显而易见的东西,并且让自己变得更加困难?

试试
Ruby及其世界一章,特别是关于环境变量的章节。摘录:

  RUBYLIB 
Ruby程序的附加搜索路径($ SAFE必须为0)。
DLN_LIBRARY_PATH
动态加载模块的搜索路径。
RUBYLIB_PREFIX
(仅适用于Windows)通过为每个组件添加此
前缀来处理RUBYLIB搜索路径。


I have a custom Ruby library directory that I'd like to have automatically added to Ruby's load path whenever Ruby is executed. I know I can use the -I option to Ruby, but I'm wondering if there is something like an environment variable that I can set that will globally determine Ruby's load path.

As an aside, my high level task is to install Ruby Gems on a Linux box where I don't have root, so I need to have a Ruby load path in a non-standard location. I've installed RubyGems per the directions at http://rubygems.org/read/chapter/3#page83 ("Installing RubyGems in a User Directory"), but the gem command isn't picking up the non-standard load path. Maybe I'm missing something obvious here and making things harder for myself?

解决方案

Try the Ruby and its world chapter from the pickaxe book, specifically the section on environment variables. Excerpt:

RUBYLIB 
  Additional search path for Ruby programs ($SAFE must be 0).
DLN_LIBRARY_PATH
  Search path for dynamically loaded modules.
RUBYLIB_PREFIX
  (Windows only) Mangle the RUBYLIB search path by adding this
  prefix to each component.

这篇关于在外部设置Ruby加载路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆