Execute perl prepending relative lib dirs to @INC
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



App::rlibperl - Execute perl prepending relative lib to @INC


version 0.700


Install this into a local::lib directory to simplify including the local::lib when calling perl:

# cron job:
* * * * * /project/dir/bin/rlibperl -MProject::App -e 'run()'

# program configuration file:
command = /home/username/perl5/bin/rlibperl -MSome::Mod -e 'do { something; }'

If you're lazy (like me) you can use it in the shebang line:


Then you don't need to add an explicit

use lib '/home/username/perl5/lib/perl5';

before any of your other code.


The rlibperl script simplifies the inclusion of relative library directories with perl.

Upon execution the script will look for lib directories relative to the location of the script then re-invoke perl with all supplied command line arguments and any found lib directories added to @INC.

The script was designed to be installed via local::lib (though local::lib is not required). Once installed, executing the script is just like executing perl except that it adds the local lib directories to @INC for you.

It also adds the directory of the script to $PATH like local::lib does which enables system/qx/exec/etc. to find executables in that directory.

So this:

$HOME/perl5/bin/rlibperl -MSome::Module -e 'do_something'

is roughly the equivalent of:

PATH=$HOME/perl5/bin:$PATH perl \
   -I$HOME/perl5/lib/perl5 -MSome::Module -e 'do_something'

If that isn't useful enough (it probably isn't) check out App::rbinperl which automatically adds -S which makes it just as easy to execute another script in that bin directory.


rlibperl will look for the following directory structures relative to the directory in which it is located:

If the script is located in a directory named bin (or script or scripts) it assumes a structure similar to local::lib and will first look for ../lib/perl5:


If not found it will check for ./lib.


(If rlibperl is not located in a directory matching /bin|scripts?/ the order will be reversed: it will look for ./lib first.)

Lastly it will check for simply ../lib.


If you have another directory structure you think should be supported please send suggestions!


The initial use-case for rlibperl was installing via local::lib (or without it using something like cpanm --local-lib /other/dir) and calling like so:

$ /path/to/local-lib/rlibperl -perl-args

(It may also be useful in a per-project setting, though it's likely easier to make custom scripts and/or use the unrelated rlib.)

The following limitations exist when used in other situations, however they are considered bugs and may be "fixed" at some point (so their functionality should not be relied upon):

  • Installing this into a perl's default lib will end up duplicating directories in @INC and probably reverse the order of your search path.

    This is a problem, but then installing rlibperl into a directory that is already in your @INC isn't all that useful.

  • Using these scripts in the shebang is arguably the most useful way to use them (and in fact the reason they were created).

    Unfortunately shebangs aren't always portable.

    Some systems don't allow using another script (as opposed to a binary) in the shebang line. You can work around this by adding a slight variation of the common eval 'exec' idiom. Just insert what would have been your shebang into the exec arguments:

    eval 'exec perl /home/username/perl5/bin/rlibperl -S $0 ${1+"$@"}'
      if 0;

If you think other functionality would be useful please submit examples, rationale, or patches.


  • App::rbinperl - included
  • local::lib - The module that makes this one useful
  • ylib (perl -Mylib) - Configurable additional lib directories
  • Devel::Local - An alternative to the above modules
  • rlib - This module is not related to or dependent on rlib but it serves a similar purpose in a different situation.
  • App::local::lib::helper - A more configurable alternative to this dist that loads local::lib and its environment variables.

    The localenv script installed by App::local::lib::helper may be more powerful as a shell tool, but rlibperl serves a few niches that localenv does not, including enabling shebang args and taint mode.

    Use the tool that works for you.



You can find documentation for this module with the perldoc command.

perldoc App::rlibperl


The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-app-rlibperl at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-rlibperl. You will be automatically notified of any progress on the request by the system.

Source Code


git clone https://github.com/rwstauner/App-rlibperl.git


Randy Stauner rwstauner@cpan.org


This software is copyright (c) 2011 by Randy Stauner.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.