I’ve encountered an error which I cannon solve by myself.
I’m working on a remote server on which I don’t have root access. In my
work (which by now doesn’t involve other server users) I need to install
some gems, but due to access limitations I cannot ask root to install
them
and/or install them from my current user.
I followed that guide: pts.blog: How to set up ruby gems on Debian Etch as non-root(since
we’re using Debian), and I managed to install gems into custom
directory, but when I try to ‘require’ them in my scripts, following
happens (using weibo2 by acenqiu as an example):
/weibo_crawler
./weibo_crawler:3:in `require’: no such file to load – weibo2
(LoadError)
from ./weibo_crawler:3
/weibo_crawler
./weibo_crawler:3:in `require’: no such file to load – weibo2 (LoadError)
from ./weibo_crawler:3
…
…
env:
…
GEM_HOME=/home/anisimovich/gems
…
When you require something, you do not require a gem. You require
either a .rb (ruby source) file or a .so (library) file.
Ruby searches these files in standard directories, plus in those
included in environment RUBYLIB. Look at where, under
/home/anisimovich/gems, the weibo.rb or weibo.so file is, and add that
directory to the content of RUBYLIB.
While it may not be exactly what you need, I really suggest looking into
RVM. It allows you to easily install any version of Ruby and any gems
straight in your home directory, entirely painlessly. even if you have
no privileges on the system.
Because you’re using Ruby 1.8.7, you need to explicitly require the
rubygems library before you can use any gems easily. That step is
missing from the blog post you referenced. You can either do this on
the command line by adding -rubygems to the ruby command line arguments
or by exporting the RUBYOPT environment variable before running your
script as follows:
export RUBYOPT=-rubygems
FYI, this additional step is not necessary for Ruby 1.9.
While it may not be exactly what you need, I really suggest looking into
RVM. It allows you to easily install any version of Ruby and any gems
straight in your home directory, entirely painlessly. even if you have no
privileges on the system.
Well, managed to run the required gems by adding folders *
/home/user/gems/gems/%gemname%/lib* to PATH, but still seems some voodoo
magic to me rather than a solution to the problem. Still, suppose can
get
along with it, since rvm isn’t quite right for our tasks.