在Ruby 2.0.0中将新目录添加到$ LOAD PATH

时间:2013-10-22 11:45:18

标签: ruby ubuntu-12.04

在这个问题上经过多个帖子后,我仍然无法将新目录添加到$LOAD_PATH。我使用的是Ubuntu 12.我的$LOAD_PATH是:

2.0.0-p247 :002 > puts $LOAD_PATH
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/vendor_ruby/2.0.0
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/vendor_ruby/2.0.0/x86_64-linux
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/vendor_ruby
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0
/home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-linux
 => nil 

如何通过终端向/home/ajax/Ruby/Projects添加“$LOAD_PATH”?

3 个答案:

答案 0 :(得分:1)

您可以使用$LOAD_PATH参数(可以使用多个ruby命令将irb的其他条目添加为-I(或$ ruby -I '/home/ajax/Ruby/Projects' -e 'puts $LOAD_PATH' /home/ajax/Ruby/Projects /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0 /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/vendor_ruby/2.0.0 /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/vendor_ruby/2.0.0/x86_64-linux /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/vendor_ruby /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0 /home/ajax/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-linux )命令的命令行参数倍)

{{1}}

答案 1 :(得分:0)

在您的终端

export RUBYLIB=/home/ajax/Ruby/Projects

答案 2 :(得分:0)

来自Add $LOAD_PATH externally

  

RUBYLIB环境变量是以冒号分隔的路径列表,ruby将在其前面添加标准LOAD_PATH。命令行中的ruby -I path也与代码中的$LOAD_PATH.unshift 'path'相同。 Ruby还将处理来自环境var RUBYOPT的选项。