Ruby cannot find required libraries even though gem is installed

时光总嘲笑我的痴心妄想 提交于 2019-12-14 01:00:33

问题


I have spent literally days trying to install ruby 1.9.2 and get it working with gems :-/ I eventually gave up on my Mac OSX 10.6 machine and below is the current state on my Ubuntu machine. Any advice would be greatly appreciated!

# ruby test.rb
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- mongo (LoadError)
 from <internal:lib/rubygems/custom_require>:29:in `require'
 from test.rb:1:in `<main>'
# cat test.rb
require 'mongo'
db = Mongo::Connection.new.db("mydb")
# gem which mongo
/usr/local/rvm/gems/ruby-1.9.2-p0/gems/mongo-1.1.2/lib/mongo.rb
# cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.10
DISTRIB_CODENAME=maverick
DISTRIB_DESCRIPTION="Ubuntu 10.10"

According to this page: http://docs.rubygems.org/read/chapter/19 I symlinked which ruby I was using to match that which gem is using:

# which ruby
/usr/local/rvm/bin/ruby
# ls -l `which ruby`
lrwxrwxrwx 1 root root 44 2010-11-17 13:25 /usr/local/rvm/bin/ruby -> /usr/local/rvm/rubies/ruby-1.9.2-p0/bin/ruby
# gem env | grep 'RUBY EXECUTABLE'
  - RUBY EXECUTABLE: /usr/local/rvm/rubies/ruby-1.9.2-p0/bin/ruby
# which gem
/usr/local/rvm/bin/gem
# gem -v
1.3.7
# ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

回答1:


Why is "rvm" displaying in your /usr/local/rvm/ path? Did you do a system-wide install, as a system administrator using administering Ruby system wide for multiple users?

Did you add [[ -s '/usr/local/lib/rvm' ]] && source '/usr/local/lib/rvm' to your ~/.bashrc, ~/.bash_profile or ~/.profile (whichever you have configured)?

For normal, every day use, I recommend RVM's default setup: RVM installation, RVM gems management.

Note to self: Buy stock in RVM. It's too cool.




回答2:


Try putting the following line at the beginning

require "rubygems"



回答3:


Does it work under Ruby 1.8.7, which is pre-installed by default on OS X?

If so, one difference between 1.9.1 and 1.9.2 is that "." isn't part of $:'s path any more.




回答4:


I recommend that you do rvm implode and delete the current setup. Then use the railsready script to setup RVM and Ruby properly for you on Ubuntu. It's important to understand that until you know what you are doing you should run the script as a user. Hope that helps.




回答5:


On linux and OS X, I have always had to put require "rubygems" in the beginning. However it has always worked fine without this line on windows.



来源:https://stackoverflow.com/questions/4207992/ruby-cannot-find-required-libraries-even-though-gem-is-installed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!