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:
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):
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.
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
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.
In fact, if I show the content of $: (or $LOAD_PATH) I get this (with
same concept).
different gemsets.
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.