Skip to content
trans edited this page Jan 7, 2013 · 3 revisions

Library Configuration

By default Library will serve up the $GEM_PATH locations. For many users that is all that is needed and this section of instruction can be skipped.

Yet Library is very flexible and can be configured in any number of manners to serve up Ruby programs. This can be done by adjusting the locations in which libraries can be found via the $RUBY_LIBRARY environment variable.

For example, lets say a developer wants to ensure that a current project's vendor location is always prepended to the library look-up to ensure the use of any modified dependencies.

    export RUBY_LIBRARY="./vendor:$GEM_PATH"

Now any submodules in a project's vendor/ directory will be accessible via require and load. While not the most robust solution, since it requires the project be run from its root directory, and only makes sense when running in live mode, it is nonetheless an easy example of how one can manipulate the $RUBY_LIBRARY environment variable.

When using a Ruby version manager, and modifying the $RUBY_LIBRARY environment variable for more general purposes, say for instance you want to serve up a special set of Ruby projects that you simply "installed" via a git checkout, you may want to differentiate sets of libraries based on your current Ruby. For example, with chruby, you might do something like:

    export RUBY_LIBRARY="~/ruby-gits/$RUBY_VERSION/:$GEM_PATH"

That way, when you change your current Ruby, you also change which libraries are available. In most cases this is not important, but if the library has any C extensions which must be compiled, then it may be vital to make this differentiation.

Another interesting feature of $RUBY_LIBRARY is that is can take a file, rather then a directory. If a path is a file it will read the file and parse it for additional paths, one for each line in the file. So for instance, one could do:

    export RUBY_LIBRARY="~/.ruby/mylibs"

And then in a file called ~/.ruby/mylibs put:

    ~/ruby-gits/$RUBY_VERSION/
    $GEM_PATH

Which would have the same effect as the prior configuration.

These are just some examples of advanced configuration. How and why a developer might adjust the $RUBY_LIBRARY setting is their call.

Clone this wiki locally