Forum: Ruby Installing and using ruby gems without root privileges

Posted by Arseni Anisimovich (Guest)
on 2013-01-11 10:39
(Received via mailing list)
Hello there!

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:
http://ptspts.blogspot.com/2009/03/how-to-set-up-r...
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


here's the first lines of script:

#!/usr/bin/ruby

require 'weibo2'

Weibo2::Config.api_key = "111111111"
Weibo2::Config.api_secret = "0101010101"

Any ideas, where I could be wrong in my actions?

PS. Ruby 1.8.7 . Gems installed @ /home/user/gems/
env:
...
GEM_HOME=/home/anisimovich/gems
...
Posted by Carlo E. Prelz (Guest)
on 2013-01-11 10:46
(Received via mailing list)
Subject: Installing and using ruby gems without root privileges
  Date: Fri 11 Jan 13 06:39:21PM +0900

Quoting Arseni Anisimovich (aruseni@gmail.com):

>
> /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.

Carlo
Posted by Bartosz DziewoƄski (matmarex)
on 2013-01-11 11:52
(Received via mailing list)
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.

https://rvm.io/
Posted by Arseni Anisimovich (Guest)
on 2013-01-11 12:23
(Received via mailing list)
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.

Thanks for the replies!

--
Best regads,
Arseni Anisimovich

mobile: +375-29-6-240-565
icq:      160-195-957
skype:  aruseni
Posted by Jeremy Bopp (Guest)
on 2013-01-11 18:02
(Received via mailing list)
On 01/11/2013 03:39 AM, Arseni Anisimovich wrote:
> http://ptspts.blogspot.com/2009/03/how-to-set-up-r...
>
> env:
> ...
> GEM_HOME=/home/anisimovich/gems
> ...

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.

-Jeremy
Posted by tamouse mailing lists (Guest)
on 2013-01-12 14:26
(Received via mailing list)
On Fri, Jan 11, 2013 at 4:51 AM, Matma Rex <matma.rex@gmail.com> wrote:
> 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.
>
> https://rvm.io/

+1 for rvm in this context. It is *necessary* to keep you from tearing
out your hair.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.