为什么 ruby 的 '$:'或“$LOAD_PATH”当我用 sudo 运行它时会改变吗?
我正在尝试以 root 身份运行 ruby 脚本。当我尝试 require
一个 gem 时,ruby 说找不到它。这是因为 $:
$ ruby -e "puts $:"
/opt/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/cgi_multipart_eof_fix-2.5.0/lib
/opt/local/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib
/opt/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib
/opt/local/lib/ruby/gems/1.9.1/gems/fastthread-1.0.7/lib
/opt/local/lib/ruby/gems/1.9.1/gems/fastthread-1.0.7/ext
/opt/local/lib/ruby/gems/1.9.1/gems/fastthread-1.0.7/bin
/opt/local/lib/ruby/gems/1.9.1/gems/gem_plugin-0.2.3/bin
/opt/local/lib/ruby/gems/1.9.1/gems/gem_plugin-0.2.3/lib
/opt/local/lib/ruby/gems/1.9.1/gems/json_pure-1.4.3/bin
/opt/local/lib/ruby/gems/1.9.1/gems/json_pure-1.4.3/lib
/opt/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/bin
/opt/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/lib
/opt/local/lib/ruby/gems/1.9.1/gems/msgpack-0.4.3/lib
/opt/local/lib/ruby/gems/1.9.1/gems/nestful-0.0.2/lib
/opt/local/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2/bin
/opt/local/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2/lib
/opt/local/lib/ruby/gems/1.9.1/gems/num_to_bytes-1.4.1/ext
/opt/local/lib/ruby/gems/1.9.1/gems/num_to_bytes-1.4.1/bin
/opt/local/lib/ruby/gems/1.9.1/gems/open4-1.0.1/lib
/opt/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/bin
/opt/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib
/opt/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin
/opt/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib
/opt/local/lib/ruby/gems/1.9.1/gems/ruby-processing-1.0.9/bin
/opt/local/lib/ruby/gems/1.9.1/gems/ruby-processing-1.0.9/lib
/opt/local/lib/ruby/gems/1.9.1/gems/ruby_parser-2.0.4/bin
/opt/local/lib/ruby/gems/1.9.1/gems/ruby_parser-2.0.4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/rubyforge-2.0.4/bin
/opt/local/lib/ruby/gems/1.9.1/gems/rubyforge-2.0.4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/sexp_processor-3.0.4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/sinatra-1.0/lib
/opt/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/bin
/opt/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib
/opt/local/lib/ruby1.9/site_ruby/1.9.1
/opt/local/lib/ruby1.9/site_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/site_ruby
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/vendor_ruby
/opt/local/lib/ruby1.9/1.9.1
/opt/local/lib/ruby1.9/1.9.1/i386-darwin10
.
$ sudo ruby -e "puts $:"
/opt/local/lib/ruby1.9/site_ruby/1.9.1
/opt/local/lib/ruby1.9/site_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/site_ruby
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/vendor_ruby
/opt/local/lib/ruby1.9/1.9.1
/opt/local/lib/ruby1.9/1.9.1/i386-darwin10
.
为什么会发生这种情况?
I am trying to run a ruby script as root. When I try to require
a gem, ruby says it can't be found. This is because of $:
$ ruby -e "puts $:"
/opt/local/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/cgi_multipart_eof_fix-2.5.0/lib
/opt/local/lib/ruby/gems/1.9.1/gems/daemons-1.1.0/lib
/opt/local/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib
/opt/local/lib/ruby/gems/1.9.1/gems/fastthread-1.0.7/lib
/opt/local/lib/ruby/gems/1.9.1/gems/fastthread-1.0.7/ext
/opt/local/lib/ruby/gems/1.9.1/gems/fastthread-1.0.7/bin
/opt/local/lib/ruby/gems/1.9.1/gems/gem_plugin-0.2.3/bin
/opt/local/lib/ruby/gems/1.9.1/gems/gem_plugin-0.2.3/lib
/opt/local/lib/ruby/gems/1.9.1/gems/json_pure-1.4.3/bin
/opt/local/lib/ruby/gems/1.9.1/gems/json_pure-1.4.3/lib
/opt/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/bin
/opt/local/lib/ruby/gems/1.9.1/gems/mongrel-1.1.5/lib
/opt/local/lib/ruby/gems/1.9.1/gems/msgpack-0.4.3/lib
/opt/local/lib/ruby/gems/1.9.1/gems/nestful-0.0.2/lib
/opt/local/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2/bin
/opt/local/lib/ruby/gems/1.9.1/gems/nokogiri-1.4.2/lib
/opt/local/lib/ruby/gems/1.9.1/gems/num_to_bytes-1.4.1/ext
/opt/local/lib/ruby/gems/1.9.1/gems/num_to_bytes-1.4.1/bin
/opt/local/lib/ruby/gems/1.9.1/gems/open4-1.0.1/lib
/opt/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/bin
/opt/local/lib/ruby/gems/1.9.1/gems/rack-1.2.1/lib
/opt/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin
/opt/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib
/opt/local/lib/ruby/gems/1.9.1/gems/ruby-processing-1.0.9/bin
/opt/local/lib/ruby/gems/1.9.1/gems/ruby-processing-1.0.9/lib
/opt/local/lib/ruby/gems/1.9.1/gems/ruby_parser-2.0.4/bin
/opt/local/lib/ruby/gems/1.9.1/gems/ruby_parser-2.0.4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/rubyforge-2.0.4/bin
/opt/local/lib/ruby/gems/1.9.1/gems/rubyforge-2.0.4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/sexp_processor-3.0.4/lib
/opt/local/lib/ruby/gems/1.9.1/gems/sinatra-1.0/lib
/opt/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/bin
/opt/local/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib
/opt/local/lib/ruby1.9/site_ruby/1.9.1
/opt/local/lib/ruby1.9/site_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/site_ruby
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/vendor_ruby
/opt/local/lib/ruby1.9/1.9.1
/opt/local/lib/ruby1.9/1.9.1/i386-darwin10
.
$ sudo ruby -e "puts $:"
/opt/local/lib/ruby1.9/site_ruby/1.9.1
/opt/local/lib/ruby1.9/site_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/site_ruby
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1
/opt/local/lib/ruby1.9/vendor_ruby/1.9.1/i386-darwin10
/opt/local/lib/ruby1.9/vendor_ruby
/opt/local/lib/ruby1.9/1.9.1
/opt/local/lib/ruby1.9/1.9.1/i386-darwin10
.
Why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 sudo -E ruby -e "puts $:" 。
从
sudo
手册页:Try
sudo -E ruby -e "puts $:"
.From the
sudo
man page: