# Best practice? own libs

**URL:** <https://www.ruby-forum.com/t/best-practice-own-libs/66581>\
**Category:** Ruby\
**Created:** [August 27, 2006, 9:49am UTC](https://www.ruby-forum.com/t/best-practice-own-libs/66581 "2006-08-27T09:49:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [August 27, 2006, 9:49am UTC](https://www.ruby-forum.com/t/best-practice-own-libs/66581/1 "2006-08-27T09:49:57Z")

</div>

Hi,

I’d like to ask you for your recommendations. I  
develop (privately) a set of libraries which are used in several  
projects. Some of these I also want to share with others (i.e.  
distribute). When developing I use a directory structure such as

lib/ \<— libraries here  
test/ \<— tests  
…

Now, when using the library from another project I either need to

1. put the above lib directory in $:, the search path
2. copy the needed libs to the project  
or
3. install the library in a system wide/private directory structure  
and set the environment variable RUBYLIB.

Of course I would always like to use the newest version of a lib.

What do you guys recommend? Symlinks?

Patrick

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [August 27, 2006, 11:17pm UTC](https://www.ruby-forum.com/t/best-practice-own-libs/66581/2 "2006-08-27T23:17:18Z")

</div>

> most noteably setup.rb ([setup.rb](http://i.loveruby.net/en/projects/setup/)), or  
> use the ruby-specific package manager, RubyGems.

Go for RubyGems. They’re simple to generate and even simpler to use. I  
am  
in a similar situation that you describe with some private libs and  
found  
it best to package them into backofficegems hosted on rubyforge.

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [August 27, 2006, 10:15am UTC](https://www.ruby-forum.com/t/best-practice-own-libs/66581/3 "2006-08-27T10:15:36Z")

</div>

Patrick G. wrote:

> What do you guys recommend? Symlinks?

Depends on your needs. But #1 and #3 aren’t portable. #2 is the right  
choice hwne you don;t want to have you lib dependent on the  
installation of another lib. In those cases I put the code in:  
lib/vendor/, although I’ve seen other use lib/support/.

The 4th option, which is the typical general approach --the one for whn  
it’s okay to have an external dependency, is to install the library to  
the a standard location. The $LOAD\_PATH is already set to search these  
locations depending on you Ruby installation. For instance, on Debian  
the location is /usr/local/lib/site\_ruby/1.8/. But really you don’t  
have to worry about that yourself if you just use an install script,  
most noteably setup.rb ([setup.rb](http://i.loveruby.net/en/projects/setup/)), or  
use the ruby-specific package manager, RubyGems.

HTH.

```
                                             trans

```

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [August 29, 2006, 1:33am UTC](https://www.ruby-forum.com/t/best-practice-own-libs/66581/4 "2006-08-29T01:33:11Z")

</div>

On Aug 27, 2006, at 12:50 AM, Patrick G. wrote:

> 1. put the above lib directory in $:, the search path
> 2. copy the needed libs to the project  
> or
> 3. install the library in a system wide/private directory structure  
> and set the environment variable RUBYLIB.
> 
> Of course I would always like to use the newest version of a lib.
> 
> What do you guys recommend? Symlinks?

ruby -I in your rake/make testing rule.

If the directories don’t exist ruby won’t care and it’ll use  
installed versions.

If they do, they’ll be picked up before gems/site\_lib.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [August 30, 2006, 1:46pm UTC](https://www.ruby-forum.com/t/best-practice-own-libs/66581/5 "2006-08-30T13:46:00Z")

</div>

Hello,

thanks all for your suggestions. I think that I go for changing $: for  
tests and running ‘setup’ before using the library from other  
applications. That way I don’t have to copy anything. But I have to  
remember running ‘setup’ or rake… after my tests run ok.

Patrick
