Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby cannot find required libraries even though gem is installed

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]
like image 445
John Avatar asked Nov 17 '10 18:11

John


3 Answers

Try putting the following line at the beginning

require "rubygems"
like image 156
asb Avatar answered Oct 11 '22 15:10

asb


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.

like image 43
the Tin Man Avatar answered Oct 11 '22 14:10

the Tin Man


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.

like image 24
Andrew Grimm Avatar answered Oct 11 '22 13:10

Andrew Grimm