# Requiring external libraries directly

**URL:** <https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773>\
**Category:** Ruby\
**Created:** [December 20, 2007, 3:48pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773 "2007-12-20T15:48:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [December 20, 2007, 3:48pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773/1 "2007-12-20T15:48:10Z")

</div>

I want to put all the external libraries I’m using in my project in a  
folder and require directly from there instead of installing the gem in  
ruby.

MyProject folder  
ExternalLibraries folder  
Watir  
rexml  
oci8  
…  
mycode requiring the libraries in ExternalLibraries if it’s needed

Is that possible?

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [December 21, 2007, 12:24pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773/2 "2007-12-21T12:24:22Z")

</div>

Any idea???

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [December 21, 2007, 3:59pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773/3 "2007-12-21T15:59:37Z")

</div>

But I’ll need the gem file in the external library folder or what??

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [December 21, 2007, 12:53pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773/4 "2007-12-21T12:53:51Z")

</div>

Mario R. wrote:

> MyProject folder  
> ExternalLibraries folder  
> Watir  
> rexml  
> oci8  
> …  
> mycode requiring the libraries in ExternalLibraries if it’s needed

Just add following string into your code (before require statements)

$:.unshift File.join(File.dirname( **FILE** ), “…”, “ExternalLibraries  
folder”)  
require …

this will add ExternalLibraries folder to the ruby load path.

Regards,  
arkadi4

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [December 21, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773/5 "2007-12-21T22:23:43Z")

</div>

Don’t trim context, we don’t know what you’re talking about when you  
do that.

On Dec 21, 2007, at 06:59 AM, Mario R. wrote:

> > I want to put all the external libraries I’m using in my project in a  
> > folder and require directly from there instead of installing the  
> > gem in  
> > ruby.
> 
> But I’ll need the gem file in the external library folder or what??

If you’re sourcing the files you want from gems, what’s wrong with  
using gems? It does everything you want without any extra hassle of  
figuring out how to get your load path correct.

---

<div class="post-metadata">

**Author:** ![tcblues](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/db5fbb/32.png) [@tcblues](https://www.ruby-forum.com/u/tcblues)\
**Post date:** [December 21, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/requiring-external-libraries-directly/123773/6 "2007-12-21T22:09:03Z")

</div>

Al Og wrote:

> $:.unshift File.join(File.dirname( **FILE** ), “…”, “ExternalLibraries  
> folder”)  
> require …

Suggestion:

Instead of:

File.dirname( **FILE** )

use this:

File.dirname(File.expand\_path( **FILE** ))

The protects you in case of Dir.chdir.
