# $LOAD\_PATH best practice?

**URL:** <https://www.ruby-forum.com/t/load-path-best-practice/161748>\
**Category:** Ruby\
**Created:** [March 2, 2009, 1:01am UTC](https://www.ruby-forum.com/t/load-path-best-practice/161748 "2009-03-02T01:01:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Burdette\_Lamar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@Burdette\_Lamar](https://www.ruby-forum.com/u/Burdette_Lamar)\
**Post date:** [March 2, 2009, 1:01am UTC](https://www.ruby-forum.com/t/load-path-best-practice/161748/1 "2009-03-02T01:01:42Z")

</div>

The local filetree corresponding to source control is not in the same  
location on all machines.

Therefore, the needed Ruby $LOAD\_PATH varies from one machine to  
another.

I can control this from a script of course. I can, for example, addthis  
to the top of a script that’s two levels below the ‘root’:

```
require 'pathname'
home_path = Pathname.new(File.join(File.dirname( __FILE__ ), 

```

‘…/…’)).realpath  
$LOAD\_PATH.push home\_path unless ($LOAD\_PATH.index(home\_path))

This works, but is it best? Is there best practice for this sort  
ofthing?

Thanks, Burdette

---

<div class="post-metadata">

**Author:** ![Burdette\_Lamar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@Burdette\_Lamar](https://www.ruby-forum.com/u/Burdette_Lamar)\
**Post date:** [March 2, 2009, 1:19am UTC](https://www.ruby-forum.com/t/load-path-best-practice/161748/2 "2009-03-02T01:19:15Z")

</div>

Burdette Lamar wrote:

> This works, but is it best? Is there best practice for this sort ofthing?
> 
> Thanks, Burdette

You can also modify the load path by setting the RUBYLIB environment  
variable, or by using the -I option on the command line. Since the load  
path is constant on a machine, I’d argue for setting RUBYLIB instead of  
modifying every script.

---

<div class="post-metadata">

**Author:** ![Burdette\_Lamar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@Burdette\_Lamar](https://www.ruby-forum.com/u/Burdette_Lamar)\
**Post date:** [March 2, 2009, 10:31am UTC](https://www.ruby-forum.com/t/load-path-best-practice/161748/3 "2009-03-02T10:31:08Z")

</div>

Hi,

At Mon, 2 Mar 2009 08:58:46 +0900,  
Burdette Lamar wrote in [ruby-talk:330039]:

> ```
> require 'pathname'
> home_path = Pathname.new(File.join(File.dirname( __FILE__ ), '../..')).realpath
> 
> ```

You don’t need pathname.

```
home_path = File.expand_path('../../..', __FILE__ )
```

---

<div class="post-metadata">

**Author:** ![Burdette\_Lamar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@Burdette\_Lamar](https://www.ruby-forum.com/u/Burdette_Lamar)\
**Post date:** [March 2, 2009, 11:25am UTC](https://www.ruby-forum.com/t/load-path-best-practice/161748/4 "2009-03-02T11:25:43Z")

</div>

Nobuyoshi N. wrote:

> Hi,

Hi.

> You don’t need pathname.

I’ve never found a need for Pathname.

What is Pathname’s purpose?

Regards,
