How to add a non standard Gem path?

Hi, I would like to install some Gems in a custom directory (i.e.
/usr/local/gems/), so such a directory will have the following
structure:

  ibc@myhost: /usr/local/gems$ ls -l

  drwxr-xr-x 2 root root 4,0K ago 29 18:02 bin/
  drwxr-xr-x 2 root root 4,0K ago 29 18:01 cache/
  drwxr-xr-x 2 root root 4,0K ago 29 18:01 doc/
  drwxr-xr-x 6 root root 4,0K ago 29 18:01 gems/
  drwxr-xr-x 2 root root 4,0K ago 29 18:02 specifications/

Once I've started a Ruby script, how can I tell the "require" command
to include my custom Gem directory so "require GEM_NAME" command looks
first in /usr/local/gems/gems/*/lib/* ?

I've tryed modifying the Gem.path which by default has this value:

  Gem.path
  => [ "/var/lib/gems/1.9.1", "/home/ibc/.gem/ruby/1.9.1"]

so I've added my directory:

  Gem.path.insert 0, "/usr/local/gems"
  Gem.path
  => ["/tmp/gems", "/var/lib/gems/1.9.1", "/home/ibc/.gem/ruby/1.9.1"]

But this does not work, "require" command does not search there.

Any help please?

Thanks a lot.

···

--
Iñaki Baz Castillo
<ibc@aliax.net>

Quoting Iñaki Baz Castillo <ibc@aliax.net>:

Hi, I would like to install some Gems in a custom directory (i.e.
/usr/local/gems/), so such a directory will have the following
structure:

  ibc@myhost: /usr/local/gems$ ls -l

  drwxr-xr-x 2 root root 4,0K ago 29 18:02 bin/
  drwxr-xr-x 2 root root 4,0K ago 29 18:01 cache/
  drwxr-xr-x 2 root root 4,0K ago 29 18:01 doc/
  drwxr-xr-x 6 root root 4,0K ago 29 18:01 gems/
  drwxr-xr-x 2 root root 4,0K ago 29 18:02 specifications/

Once I've started a Ruby script, how can I tell the "require" command
to include my custom Gem directory so "require GEM_NAME" command looks
first in /usr/local/gems/gems/*/lib/* ?

I've tryed modifying the Gem.path which by default has this value:

  Gem.path
  => [ "/var/lib/gems/1.9.1", "/home/ibc/.gem/ruby/1.9.1"]

so I've added my directory:

  Gem.path.insert 0, "/usr/local/gems"
  Gem.path
  => ["/tmp/gems", "/var/lib/gems/1.9.1", "/home/ibc/.gem/ruby/1.9.1"]

But this does not work, "require" command does not search there.

You can try something like this:

$:.unshift yourdirectory

or use rvm (https://rvm.io/\) <- you can use different ruby versions and different gemsets.

or use GEM_HOME http://docs.rubygems.org/read/chapter/3

I usually rvm and works very good.

regards
jordi

···

Any help please?

Thanks a lot.

--
Iñaki Baz Castillo
<ibc@aliax.net>

You can try something like this:

$:.unshift yourdirectory

Hi, that is not what I'm looking for. $: is the same as $LOAD_PATH and
contains directories in which Ruby searchs for libraries which
"require" command. This is not the same as adding a new directory for
Gem search.

In fact, if I show the content of $: (or $LOAD_PATH) I get this (with
Ruby 1.9 so rubygem is loaded):

["/usr/local/lib/site_ruby/1.9.1",
"/usr/local/lib/site_ruby/1.9.1/x86_64-linux",
"/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.9.1",
"/usr/lib/ruby/vendor_ruby/1.9.1/x86_64-linux",
"/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.9.1",
"/usr/lib/ruby/1.9.1/x86_64-linux"]

There is NOT the Gems directory (and it shouldn't since it's not the
same concept).

This is: I need to install several gems into /usr/local/gems/
directory and make "require" to look there as now it looks in
/var/lib/gems/1.9.1/ directory.

or use rvm (https://rvm.io/\) <- you can use different ruby versions and
different gemsets.

I cannot do that. It is not for something I need in my computer but
for a library to be published.

or use GEM_HOME http://docs.rubygems.org/read/chapter/3

Yes, I can do this (assuming that I've installed the gem "abcd" in
/usr/local/gems/"):

  export GEM_PATH=/usr/local/gems
  irb -r abcd

It works, but could I load any other Gem installed in the default
/var/lib/gems/1.9.1/ directory? I've tested it right now and got a
failure and a success, not sure yet... XD

Thanks a lot.

···

2012/8/29 Jordi Massaguer Pla <jmassaguerpla@suse.de>:

--
Iñaki Baz Castillo
<ibc@aliax.net>

Quoting Iñaki Baz Castillo <ibc@aliax.net>:

You can try something like this:

$:.unshift yourdirectory

Hi, that is not what I'm looking for. $: is the same as $LOAD_PATH and
contains directories in which Ruby searchs for libraries which
"require" command. This is not the same as adding a new directory for
Gem search.

In fact, if I show the content of $: (or $LOAD_PATH) I get this (with
Ruby 1.9 so rubygem is loaded):

["/usr/local/lib/site_ruby/1.9.1",
"/usr/local/lib/site_ruby/1.9.1/x86_64-linux",
"/usr/local/lib/site_ruby", "/usr/lib/ruby/vendor_ruby/1.9.1",
"/usr/lib/ruby/vendor_ruby/1.9.1/x86_64-linux",
"/usr/lib/ruby/vendor_ruby", "/usr/lib/ruby/1.9.1",
"/usr/lib/ruby/1.9.1/x86_64-linux"]

There is NOT the Gems directory (and it shouldn't since it's not the
same concept).

This is: I need to install several gems into /usr/local/gems/
directory and make "require" to look there as now it looks in
/var/lib/gems/1.9.1/ directory.

or use rvm (https://rvm.io/\) <- you can use different ruby versions and
different gemsets.

I cannot do that. It is not for something I need in my computer but
for a library to be published.

or use GEM_HOME http://docs.rubygems.org/read/chapter/3

Yes, I can do this (assuming that I've installed the gem "abcd" in
/usr/local/gems/"):

  export GEM_PATH=/usr/local/gems
  irb -r abcd

It works, but could I load any other Gem installed in the default
/var/lib/gems/1.9.1/ directory? I've tested it right now and got a
failure and a success, not sure yet... XD

Thanks a lot.

what you are describing sound a lot like using bundler. With bundler you can install gems inside a "vendor" directory and when you start your application with "bundler exec aaa" it loads those. Actually rails uses bundler for managing the gems.

http://gembundler.com/

regards
jordi

···

2012/8/29 Jordi Massaguer Pla <jmassaguerpla@suse.de>:

--
Iñaki Baz Castillo
<ibc@aliax.net>

It makes lot of sense, I will take a look.

Thanks a lot.

···

2012/8/29 Jordi Massaguer Pla <jmassaguerpla@suse.de>:

what you are describing sound a lot like using bundler. With bundler you can
install gems inside a "vendor" directory and when you start your application
with "bundler exec aaa" it loads those. Actually rails uses bundler for
managing the gems.

http://gembundler.com/

--
Iñaki Baz Castillo
<ibc@aliax.net>