# $LOAD\_PATH and different OSes

**URL:** <https://www.ruby-forum.com/t/load-path-and-different-oses/151504>\
**Category:** Ruby\
**Created:** [October 22, 2008, 8:22am UTC](https://www.ruby-forum.com/t/load-path-and-different-oses/151504 "2008-10-22T08:22:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 22, 2008, 8:22am UTC](https://www.ruby-forum.com/t/load-path-and-different-oses/151504/1 "2008-10-22T08:22:32Z")

</div>

Looking for best practice guidance on dealing with differing paths to  
libraries & gems amongst OSes.

I can write some reasonably decent Ruby at this point, but still a  
padawan when it comes to really understanding the whole \*nix ENV thing.

I get that ruby has some default places it looks, and that I can  
manually add paths to $LOAD\_PATH, but now I’m starting to develop and  
deploy on different OSes, and I find that my dev system finds libs and  
gems that my server doesn’t find.

I can use symlinks to force common paths, or I can put both dev and  
server paths into $LOAD\_PATHS, but both of these methods are obviously  
hokey. I bet there’s a better way, and I bet that somehow it involves  
paths in etc/profile file, but just not sure how it all goes together.  
Is setting path vars in profile on multiple machines really any better  
than setting up symlinks? It’s still customizing each box (automation is  
my friend I know).

I have at least found #!/usr/bin/env ruby to get past hard coded paths  
for that.

dev system = OS X 10.4, servers will be 10.4, 10.5, and sometimes Cent  
OS variants.

So, any suggestions for the Right Wayâ„¢ ?

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 22, 2008, 8:31pm UTC](https://www.ruby-forum.com/t/load-path-and-different-oses/151504/2 "2008-10-22T20:31:40Z")

</div>

Martin B. wrote:

> I suggest to use rubygems, even if you don’t write libraries or plan to  
> publish your program.

I have considered gems (still unsure how to ‘serve’ them privately), but  
since you brought it up, the scenario that prompted this message was  
that it was precisely an installed gem that was causing my problems –  
the mysql one.

I installed it on a fresh server and discovered that it was not  
automatically being found (but it was being found on my dev box). I  
output $LOAD\_PATH and AFAICT there were no paths that pointed to any GEM  
folders, so I am having to do that manually in my app code.

My own libraries I am not having any problems with, it was the  
differences in GEM paths between the OSes that was causing my problem.

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 22, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/load-path-and-different-oses/151504/3 "2008-10-22T21:04:05Z")

</div>

On Wed, Oct 22, 2008 at 2:30 PM, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> automatically being found (but it was being found on my dev box). I  
> output $LOAD\_PATH and AFAICT there were no paths that pointed to any GEM  
> folders, so I am having to do that manually in my app code.

Make sure you’re doing “require ‘rubygems’” at the top of your script  
in question.

You could also check the environment variable RUBYOPT, you can use it  
to automatically require rubygems.

RUBYOPT=‘rubygems’

HTH,  
Michael G.

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 22, 2008, 9:45am UTC](https://www.ruby-forum.com/t/load-path-and-different-oses/151504/4 "2008-10-22T09:45:13Z")

</div>

I suggest to use rubygems, even if you don’t write libraries or plan to  
publish your program.

Your layout then should look something like:  
.  
|-- bin  
|-- lib  
| `-- your_project_name`– tests

Now, for all executables that are in ‘bin’ first line of code:

$: \<\< File.expand\_path(File.dirname( **FILE** ) + ‘/…/lib’)

This allows you to run the development code, but once installed it will  
use  
the installed files from rubygems.

To deploy, just ‘gem install your\_project.gem’ … your libs will be  
found and  
the executables are copied in the right place no matter which OS  
(assuming  
your gemspec file defines ‘bindir’ and ‘executables’).

Martin

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [October 22, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/load-path-and-different-oses/151504/5 "2008-10-22T21:18:21Z")

</div>

Michael G. wrote:

> On Wed, Oct 22, 2008 at 2:30 PM, Greg W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > automatically being found (but it was being found on my dev box). I  
> > output $LOAD\_PATH and AFAICT there were no paths that pointed to any GEM  
> > folders, so I am having to do that manually in my app code.
> 
> Make sure you’re doing “require ‘rubygems’” at the top of your script  
> in question.

Aha! That puts some pieces together. Thanks.

– gw
