Multiple GEM repositories

I have a Ruby script which runs fine on my own machine that I’d like to
setup a Cronjob for to run on my web space provider’s server. The latter
has been setup so that a number of “system” gems are pre-installed for
all users in a global gem respository. Any additional gems a user might
require must be installed by that user using the provider’s CPanel
RubyGem utility, which places such gems into a second, local, user
specific, gem repository.

For test purposes, I created a script that simply ‘requires’ two gems -
the first global and the second local - with a print statement before
and after.

Initially, I got an error on the first require statement and determined
that the reason was because the RUBYOPT environment variable was not set
to -rubygems, as it is on my own machine.

After ensuring that option was specified, I then got an error on the
second require statement and determined that the reason was because the
GEM_PATH environment variable was not set to my local (i.e. second)
respository.

After ensuring that environment variable was set, I no longer got an
error, but I also didn’t get any output from the print statement
following the two requires.

Taking this to mean that the local gem was not successfully loading, I
tried adding appending the path to my local gem repository’s bin folder
to the PATH environment variable, but this didn’t help any.

I’m not sure what else to try at this point.

Does anyone have any suggestions.

Any assistance you could provide would be much appreciated! :slight_smile:

On Jul 18, 2008, at 12:13 PM, Rob M. wrote:

Taking this to mean that the local gem was not successfully loading, I
tried adding appending the path to my local gem repository’s bin
folder
to the PATH environment variable, but this didn’t help any.

Set GEM_HOME to be the user repository, and have the user repository
come first in GEM_PATH.

On Jul 22, 2008, at 4:35 PM, Eric H. wrote:

Set GEM_HOME to be the user repository, and have the user repository
come first in GEM_PATH.

has this been fixed? there was a time when the lookup was reversed
and had to come last…

a @ http://codeforpeople.com/

On Jul 22, 2008, at 17:33 PM, ara.t.howard wrote:

On Jul 22, 2008, at 4:35 PM, Eric H. wrote:

Set GEM_HOME to be the user repository, and have the user
repository come first in GEM_PATH.

has this been fixed? there was a time when the lookup was reversed
and had to come last…

Yes, in 1.1.0

Eric H. wrote:

On Jul 22, 2008, at 17:33 PM, ara.t.howard wrote:

On Jul 22, 2008, at 4:35 PM, Eric H. wrote:

Set GEM_HOME to be the user repository, and have the user
repository come first in GEM_PATH.

has this been fixed? there was a time when the lookup was reversed
and had to come last…

Yes, in 1.1.0

I tried as you suggested, Eric, but it actually resulted in the print
statement after the FIRST require no longer executing!

If, as Ara suggested, I set these environment variables to the path for
the global repository first, followed by that for the local one, then
things returned to where they were before these changes (i.e. whereby
the print statement after the second require no longer executes).

Shouldn’t there be either an error or an exception if these print
statements aren’t executing? I’m not getting either.

On Jul 22, 2008, at 11:57 PM, Eric H. wrote:

Yes, in 1.1.0

hrm - what’s wrong with this then

cfp:~ > cd /tmp

cfp:/tmp > gemdir arrayfields
/opt/local/lib/ruby/gems/1.8/gems/arrayfields-4.6.0

cfp:/tmp > mkdir -p ./gems/1.8/gems/ && cp -r gemdir arrayfields ./
gems/1.8/gems/

cfp:/tmp > echo ‘raise “foobar”’ >> ./gems/1.8/gems/arrayfields-4.6.0/
lib/arrayfields.rb

cfp:/tmp > ruby gems/1.8/gems/arrayfields-4.6.0/lib/arrayfields.rb
gems/1.8/gems/arrayfields-4.6.0/lib/arrayfields.rb:436: foobar
(RuntimeError)

cfp:/tmp > GEM_PATH=./gems/1.8/ ruby -r rubygems -e’ p Gem.path ’
["./gems/1.8/", “/opt/local/lib/ruby/gems/1.8”]

cfp:/tmp > GEM_PATH=./gems/1.8/ ruby -r rubygems -e’ require
“arrayfields”; p Arrayfields.version ’
“4.6.0”

cfp:/tmp > GEM_PATH=./gems/1.8/ ruby -r rubygems -e’ p Gem.path; gem
“arrayfields”, “4.6.0”; p $LOAD_PATH.first(2) ’
["./gems/1.8/", “/opt/local/lib/ruby/gems/1.8”]
["/opt/local/lib/ruby/gems/1.8/gems/arrayfields-4.6.0/bin", “/opt/
local/lib/ruby/gems/1.8/gems/arrayfields-4.6.0/lib”]

what am i doing wrong? i’ve never been able to make gem_path behave…

cheers.

a @ http://codeforpeople.com/

On Jul 23, 2008, at 09:29 AM, ara.t.howard wrote:

On Jul 22, 2008, at 11:57 PM, Eric H. wrote:

Yes, in 1.1.0

hrm - what’s wrong with this then

cfp:/tmp > mkdir -p ./gems/1.8/gems/ && cp -r gemdir arrayfields ./
gems/1.8/gems/

Use gem install, there is no ./gems/1.8/specifications/, so RubyGems
will not see any gems.

cfp:/tmp > GEM_PATH=./gems/1.8/ ruby -r rubygems -e’ p Gem.path ’
["./gems/1.8/", “/opt/local/lib/ruby/gems/1.8”]

To double-check your work, 1.2 will show the repository the gem is
found in:

GEM_PATH=./gems/1.8 gem list -d arrayfields

Here’s what I did:

$ sudo gem install arrayfields --no-rdoc --no-ri
Successfully installed arrayfields-4.6.0
1 gem installed

$ rm -fr ~/tmp/gems

$ gem install arrayfields -i ~/tmp/gems --no-rdoc --no-ri
Successfully installed arrayfields-4.6.0
1 gem installed

$ echo ‘raise “foobar”’ >> ~/tmp/gems/gems/arrayfields-4.6.0/lib/
arrayfields.rb

$ ruby !$
ruby ~/tmp/gems/gems/arrayfields-4.6.0/lib/arrayfields.rb
/Users/drbrain/tmp/gems/gems/arrayfields-4.6.0/lib/arrayfields.rb:436:
foobar (RuntimeError)

$ GEM_PATH=~/tmp/gems gem env path
/Users/drbrain/tmp/gems:/Library/Ruby/Gems/1.8

$ GEM_PATH=~/tmp/gems gem list -d array

*** LOCAL GEMS ***

arrayfields (4.6.0)
Author: Ara T. Howard
Homepage: http://codeforpeople.com/lib/ruby/arrayfields/
Installed at: /Users/drbrain/tmp/gems

 arrayfields

$ GEM_PATH=~/tmp/gems ruby -rubygems -e ‘require “arrayfields”’
/Users/drbrain/tmp/gems/gems/arrayfields-4.6.0/lib/arrayfields.rb:436:
foobar (RuntimeError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:in
gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:32:inrequire’
from -e:1

On Jul 23, 2008, at 11:30 AM, Eric H. wrote:

Use gem install, there is no ./gems/1.8/specifications/, so
RubyGems will not see any gems.

yeah just realized that - this is what i did

cfp:/tmp > GEM_HOME=./gem_home gem install arrayfields
Successfully installed arrayfields-4.6.0
1 gem installed

cfp:/tmp > GEM_HOME=./gem_home GEM_PATH=./gem_home ruby -r rubygems -
e’ p Gem.path; gem “arrayfields”, “4.6.0”; p $LOAD_PATH.first(2) ’
["./gem_home"]
["/private/tmp/gem_home/gems/arrayfields-4.6.0/bin", “/private/tmp/
gem_home/gems/arrayfields-4.6.0/lib”]

cfp:/tmp > GEM_HOME=./gem_home GEM_PATH=./gem_home:/opt/local/lib/ruby/
gems/1.8/ ruby -r rubygems -e’ p Gem.path; gem “arrayfields”, “4.6.0”;
p $LOAD_PATH.first(2) ’
["./gem_home", “/opt/local/lib/ruby/gems/1.8/”]
["/private/tmp/gem_home/gems/arrayfields-4.6.0/bin", “/private/tmp/
gem_home/gems/arrayfields-4.6.0/lib”]

cfp:/tmp > GEM_HOME=./gem_home GEM_PATH=/opt/local/lib/ruby/gems/
1.8/:./gem_home ruby -r rubygems -e’ p Gem.path; gem “arrayfields”,
“4.6.0”; p $LOAD_PATH.first(2) ’
["/opt/local/lib/ruby/gems/1.8/", “./gem_home”]
["/opt/local/lib/ruby/gems/1.8/gems/arrayfields-4.6.0/bin", “/opt/
local/lib/ruby/gems/1.8/gems/arrayfields-4.6.0/lib”]

so indeed, the bug is fixed. thanks!

a @ http://codeforpeople.com/

Rob M. wrote:

Eric H. wrote:

On Jul 22, 2008, at 17:33 PM, ara.t.howard wrote:

On Jul 22, 2008, at 4:35 PM, Eric H. wrote:

Set GEM_HOME to be the user repository, and have the user
repository come first in GEM_PATH.

has this been fixed? there was a time when the lookup was reversed
and had to come last…

Yes, in 1.1.0

I tried as you suggested, Eric, but it actually resulted in the print
statement after the FIRST require no longer executing!

If, as Ara suggested, I set these environment variables to the path for
the global repository first, followed by that for the local one, then
things returned to where they were before these changes (i.e. whereby
the print statement after the second require no longer executes).

Shouldn’t there be either an error or an exception if these print
statements aren’t executing? I’m not getting either.

Problem resolved!

After remembering how the very first gem I tried to install in my LOCAL
repository (quite some time ago now) had caused some errors at the time
(specifically, because it was already installed in the global
repository), I decided to try deinstalling all gems, deleting any
remaining remnants of the local repository, and reinstalling the ones I
needed from scratch.

And that solved the problem! Assuming, that is, that I set GEM_PATH to
the local repository followed by the global one and not the reverse.

So, in the end, you were right Eric! (Though it wasn’t necessary, for me
at least, to set GEM_HOME to anything, presumably because the CPanel
Ruby Gem Installer takes care of that.)

Thanks a lot, you two - now I can proceed (hopefully a non-trivial
amount) further!

Best,

Rob

On Jul 24, 2008, at 11:05 AM, Rob M. wrote:

So, in the end, you were right Eric! (Though it wasn’t necessary,
for me
at least, to set GEM_HOME to anything, presumably because the CPanel
Ruby Gem Installer takes care of that.)

I recommend setting GEM_HOME so you don’t have to think about what
gem install will try to do. It is not used for activating gems.

Eric H. wrote:

On Jul 24, 2008, at 11:05 AM, Rob M. wrote:

So, in the end, you were right Eric! (Though it wasn’t necessary,
for me
at least, to set GEM_HOME to anything, presumably because the CPanel
Ruby Gem Installer takes care of that.)

I recommend setting GEM_HOME so you don’t have to think about what
gem install will try to do. It is not used for activating gems.

Sorry, but I think you’re missing my point. I don’t have the privileges
to open a terminal on the server (instead using CPanel’s UI for
configuring the CronJob I referred to at the beginning of this topic
discussion), so I don’t/wouldn’t manually run ‘gem install’ on the
server manually/directly. CPanel’s Gem Installer is pre-configured with
UI that allows you to see what gems are installed in the web server’s
global repository and only allows you to install new gems into your
personal local repository.

So not only do I not have to think about what ‘gem install’ will do, I
have no control over it in the first place.

On Jul 25, 2008, at 08:09 AM, Rob M. wrote:

Sorry, but I think you’re missing my point. I don’t have the
privileges
to open a terminal on the server (instead using CPanel’s UI for
configuring the CronJob I referred to at the beginning of this topic
discussion), so I don’t/wouldn’t manually run ‘gem install’ on the
server manually/directly. CPanel’s Gem Installer is pre-configured
with
UI that allows you to see what gems are installed in the web server’s
global repository and only allows you to install new gems into your
personal local repository.

Oh, ok, that’s pretty neat!

Initially, I got an error on the first require statement and determined
that the reason was because the RUBYOPT environment variable was not set
to -rubygems, as it is on my own machine.

After ensuring that option was specified, I then got an error on the
second require statement and determined that the reason was because the
GEM_PATH environment variable was not set to my local (i.e. second)
respository.

After ensuring that environment variable was set, I no longer got an
error, but I also didn’t get any output from the print statement
following the two requires.

You said you didnt have access to shell, how did you set these
variables? Did you send in a request of something?

Arvind Raj wrote:

Initially, I got an error on the first require statement and determined
that the reason was because the RUBYOPT environment variable was not set
to -rubygems, as it is on my own machine.

After ensuring that option was specified, I then got an error on the
second require statement and determined that the reason was because the
GEM_PATH environment variable was not set to my local (i.e. second)
respository.

After ensuring that environment variable was set, I no longer got an
error, but I also didn’t get any output from the print statement
following the two requires.

You said you didnt have access to shell, how did you set these
variables? Did you send in a request of something?

I switched to having the Cron job I mentioned above run a shell script
which sets the variables and then runs the Ruby script.

In case that wasn’t clear, I do have access to the shell through Cron
jobs set up via CPanel - it’s an interactive terminal on the server I
don’t have access to.