# Using local gems

**URL:** <https://www.ruby-forum.com/t/using-local-gems/116098>\
**Category:** Rails\
**Created:** [October 2, 2007, 11:53am UTC](https://www.ruby-forum.com/t/using-local-gems/116098 "2007-10-02T11:53:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 11:53am UTC](https://www.ruby-forum.com/t/using-local-gems/116098/1 "2007-10-02T11:53:27Z")

</div>

Hello,

I have successfully installed some local gems on my rails host. I  
checked that through irb:

irb(main):002:0\> require ‘rubygems’  
=\> true  
irb(main):003:0\> require\_gem ‘mylocalgem’  
=\> true  
irb(main):003:0\> a = MyLocalGem::MyClass.new  
=\> #\<MyLocalGem::MyClass:0x409a343c [bunch of stuff from MyClass]\>

I’m still unable to make my rails application use that gem.

config/environment.rb (at the end):  
ENV[‘GEM\_PATH’] = ‘/usr/lib/ruby/gems/1.8:/my/path/to/local/gems’

app/helpers/application\_helper.rb:  
require ‘rubygems’  
require\_gem ‘mylocalgem’  
module ApplicationHelper  
end

app/controllers/user\_controller.rb:  
[…]  
def show\_myclass  
@myclass = MyLocalGem::MyClass.new  
end  
[…]

And when I browse to /user/show\_myclass, I get:  
NameError in UserController#show\_myclass  
uninitialized constant UserController::MyLocalGem  
#{RAILS\_ROOT}/app/controllers/user\_controller.rb:265:in  
`show\_myclass’

What did I miss?

Thanks,  
Karine

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 12:06pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/2 "2007-10-02T12:06:54Z")

</div>

Hi Karine

How about installing Aptana Radrails, there is a GEM manager for you  
to use.

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 12:20pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/3 "2007-10-02T12:20:57Z")

</div>

On 2 Oct 2007, at 10:52, edhel wrote:

> I’m still unable to make my rails application use that gem.
> 
> config/environment.rb (at the end):  
> ENV[‘GEM\_PATH’] = ‘/usr/lib/ruby/gems/1.8:/my/path/to/local/gems’
> 
> app/helpers/application\_helper.rb:  
> require ‘rubygems’  
> require\_gem ‘mylocalgem’  
> module ApplicationHelper  
> end

ApplicationHelper is really not for that. it’s probably not even  
loaded at the point your show\_myclass action is called.  
Stick your require\_gem ‘mylocalgem’ in environment.rb

Fred

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 12:39pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/4 "2007-10-02T12:39:42Z")

</div>

On Oct 2, 12:05 pm, CCH [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How about installing Aptana Radrails, there is a GEM manager for you  
> to use.

I only have SSH access to that host, sorry.

Karine

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 12:50pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/5 "2007-10-02T12:50:15Z")

</div>

On 2 Oct 2007, at 11:39, edhel wrote:

> > ApplicationHelper is really not for that. it’s probably not even  
> > loaded at the point your show\_myclass action is called.  
> > Stick your require\_gem ‘mylocalgem’ in environment.rb
> 
> OK, thanks for that good practice information, though it did not fix  
> the problem.

You might need the ENV[‘GEM\_PATH’] stuff before rubygems is required.  
have you tried doing export GEM\_PATH=foo in a shell before starting  
the mongrels (or whatever it is you’re using) ?

Is it still throwing an uninitalized constant error or is the require  
itself failing ? If the require isn’t failing then it’s probably  
nothing to do with where the gem is etc…

Fred

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 1:09pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/6 "2007-10-02T13:09:41Z")

</div>

On Oct 2, 12:49 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> You might need the ENV[‘GEM\_PATH’] stuff before rubygems is required.

Wow, indeed, that was so obvious I’m ashamed I didn’t think about it.  
The problem is still there though.

> have you tried doing export GEM\_PATH=foo in a shell before starting  
> the mongrels (or whatever it is you’re using) ?

I’m not starting anything, my host has its webserver configured  
properly to serve rails apps. GEM\_PATH is in my .bash\_profile, which  
may have helped irb to find the gem, but I’m surprised ENV[‘GEM\_PATH’]  
in environment.rb is not enough to make it work for the rails app.

> Is it still throwing an uninitalized constant error or is the require  
> itself failing ? If the require isn’t failing then it’s probably  
> nothing to do with where the gem is etc…

Yes, still the same unitialized constant error.

Thanks for trying to nail down the issue, I guess I will have to ask  
my host if they have any specific config that causes this problem…

Karine

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 1:17pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/7 "2007-10-02T13:17:55Z")

</div>

On 2 Oct 2007, at 12:08, edhel wrote:

> > have you tried doing export GEM\_PATH=foo in a shell before starting  
> > the mongrels (or whatever it is you’re using) ?
> 
> I’m not starting anything, my host has its webserver configured  
> properly to serve rails apps. GEM\_PATH is in my .bash\_profile, which  
> may have helped irb to find the gem, but I’m surprised ENV[‘GEM\_PATH’]  
> in environment.rb is not enough to make it work for the rails app.

Surely there is something you can start or restart: if you don’t  
restart whatever is picking up your rails code then it won’t pick up  
changes to environment.rb  
It’s entirely possible .bash\_profile only read when a shell is  
invoked, and not in other cases (I can never remember the difference  
between all those files)

Fred

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 2:54pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/8 "2007-10-02T14:54:09Z")

</div>

On Oct 2, 1:16 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Surely there is something you can start or restart: if you don’t  
> restart whatever is picking up your rails code then it won’t pick up  
> changes to environment.rb

Well done! I killed the running dispatch.fcgi processes, a new one was  
spawned and the config files re-read. Everything is working fine now,  
many thanks 🙂

Karine

---

<div class="post-metadata">

**Author:** ![edhel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/919ad9/32.png) [@edhel](https://www.ruby-forum.com/u/edhel)\
**Post date:** [October 2, 2007, 12:39pm UTC](https://www.ruby-forum.com/t/using-local-gems/116098/9 "2007-10-02T12:39:42Z")

</div>

On Oct 2, 12:20 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > app/helpers/application\_helper.rb:  
> > require ‘rubygems’  
> > require\_gem ‘mylocalgem’  
> > module ApplicationHelper  
> > end
> 
> ApplicationHelper is really not for that. it’s probably not even  
> loaded at the point your show\_myclass action is called.  
> Stick your require\_gem ‘mylocalgem’ in environment.rb

OK, thanks for that good practice information, though it did not fix  
the problem.

I should note the same rails app is working fine on my development  
server, where the gem is installed in /usr/lib… (and I only need  
“require ‘mylocalgem’” to make it work, of course). So it’s really a  
configuration problem involving gems installed in a local prefix.

Karine
