在这个问题上经过多个帖子后,我仍然无法将新目录添加到$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
”?
答案 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)
RUBYLIB
环境变量是以冒号分隔的路径列表,ruby将在其前面添加标准LOAD_PATH。命令行中的ruby -I path
也与代码中的$LOAD_PATH.unshift 'path'
相同。 Ruby还将处理来自环境var RUBYOPT的选项。