Can't find local gems installed on hosted server

4 views
Skip to first unread message

lsiden

unread,
Oct 27, 2009, 1:59:27 PM10/27/09
to Detroit.rb
I am trying to run Sinatra on a hosted server (a2host.com). I ran
"gem install sinatra" and now I've got:

# ls ruby/gems/gems/
rack-1.0.1/ sinatra-0.9.4/

But if I try to run this little script, 'hi.rb':

require 'rubygems'
puts $:
require 'sinatra'
get '/hi' do
"Hello World!"
end

It dumps:

# ruby -I/home/lsiden/ruby/gems hi.rb
/home/lsiden/ruby/gems
/usr/lib/ruby/site_ruby/1.8
/usr/lib/ruby/site_ruby/1.8/x86_64-linux
/usr/lib/ruby/site_ruby
/usr/lib/ruby/vendor_ruby/1.8
/usr/lib/ruby/vendor_ruby/1.8/x86_64-linux
/usr/lib/ruby/vendor_ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/x86_64-linux
.
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require': no such file to load -- sinatra (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
from hi.rb:3


IOW, even though I added /home/lsiden/ruby/gems to the path ($:), it
still can't find it.

Anyone know what I'm missing?

Daniel Parker

unread,
Oct 27, 2009, 2:24:15 PM10/27/09
to rubyd...@googlegroups.com
$: is for Ruby's simple load path, while Rubygems uses its own paths:

Run this to see where they are:
    gem environment

To add to Rubygems' path is a little more cumbersome. There are several ways to do it, but I recommend #4-5 at http://wiki.a2hosting.com/index.php/How_to_install_your_own_Ruby_Gems.
    
If you need to do it within ruby rather than as a config file, do this:
    ENV['GEM_PATH']="/abs/path/to/gems:#{Gem.path.join(':')}"
    Gem.clear_paths
Rubygems is now set to use your path as well as the others.

- daniel parker -

"You have granted me life and steadfast love, and your care has preserved my spirit." Job 10:12
"The LORD is my chosen portion and my cup . . . indeed, I have a beautiful inheritance." Psalm 16:5-6
"Give what you can ... take nothing back!"

Larry Siden

unread,
Oct 27, 2009, 9:25:09 PM10/27/09
to rubyd...@googlegroups.com
Check this out.  When I SSH'd to my hosting site and did "vim .gemrc" I saw this in the editor:

---
gem: --remote --gen-rdoc --run-tests
gemhome: /home/lsiden/ruby/gems
gempath: []

rdoc: --inline-source --line-numbers

I think that part of the problem is that "gem install" puts them in ~/ruby/gems/gems instead of ~/ruby/gems.  Don't know why.

Ahhh.  I see the problem now:

#gem environment

...
  - GEM PATHS:
     - /usr/lib/ruby/gems/1.8
     - /home/lsiden/.gem/ruby/1.8
...

But then why would "gem install ..." put stuff in ~/ruby/gems/gems?  I'll try it with -i ~/ruby/gems/gems.

Nope.  Had to edit .gemrc like so:

# cat .gemrc
---
gem: --remote --gen-rdoc --run-tests
--- gemhome: /home/lsiden/ruby/gems
gemhome: /home/lsiden/.gem/ruby/1.8/gems
gempath: []

rdoc: --inline-source --line-numbers
---------------

# gem install sinatra
WARNING:  Installing to ~/.gem since /usr/lib/ruby/gems/1.8 and
      /usr/bin aren't both writable.
WARNING:  You don't have /home/lsiden/.gem/ruby/1.8/bin in your PATH,
      gem executables will not run.
Successfully installed rack-1.0.1
Successfully installed sinatra-0.9.4
2 gems installed
...

# ruby hi.rb
== Sinatra/0.9.4 has taken the stage on 4567 for development with backup from Mongrel


Much better!


Larry Siden
http://umich.edu/~lsiden
734-926-9614
skype: lsiden
Reply all
Reply to author
Forward
0 new messages