neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

If I make my own perl module, were do install it under /usr/lib/perl5 (OS is Linux)? I have several directories there:

5.8.0
5.8.2
site_perl
vendor_perl

Where is the correct place?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Where to install my own perl modules?
by DamnDirtyApe (Curate) on Mar 28, 2004 at 19:06 UTC

    I'm using Linux, so what I do is make a directory under my home directory called perl_modules, and put them in there. Then, in my .bashrc file, I put

    export PERL5LIB=~/perl_modules

    and my ~/perl_modules is automatically included in @INC for all my perl scripts.


    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
Re: Where to install my own perl modules?
by Happy-the-monk (Canon) on Mar 28, 2004 at 17:15 UTC

    You can put them wherever you want, as long as that place is included in @INC.
    Even if it isn't, you can point your programmes to the place where you've installed them like this:
    use lib qw( /path/to/my/modules /other/path/to/many/more/of/my/modules );

    Regarding your suggestions above, you would put them into ../site_perl/5.8.2 if 5.8.2 is your current Perl.

    Cheers, Sören

    Update:
    Now isn't it funny that I just run across this thread from 2000: how to include a directory in @INC?

Re: Where to install my own perl modules?
by tinita (Parson) on Mar 28, 2004 at 17:10 UTC
    i would start with h2xs as described in perlnewmod.
    then create a distribution out of your module, and it should be installable automatically with perl Makefile.PL etc. or CPAN.pm. perl then will take care of the right directory.
Re: Where to install my own perl modules?
by blue_cowdawg (Monsignor) on Mar 28, 2004 at 21:47 UTC

        If I make my own perl module, were do install it

    As the resident "Perlmeister" where I work I wrestle with that question all the time. There are several options that I use depending on the situation:

    Some preconditions to consider:

    The first thing I have to say to pre-qualify all that I am going to say on this subject is the fact we have a convention where I work that all third party software installed on our supported systems goes into /usr/local/software and each software package goes into its own subdirectory with some sort of revision tag in its name. Example we would put Perl version 5.8 into a subdirectory under /usr/local/software/perl-5.8 with appropriate symbolic links to places like /usr/bin and /usr/lib etc. This makes it real easy to deploy new versions of things onto our supported systems and roll back if necessary and other options.

    Application Specific Modules

    Keeping that scheme in mind if I or someone on my team has written a module specific to a patricular application then that module is going to get installed in the subdirectory that the application has been installed in. For instance if I have an application called "mailStripper" and its version number is 2.1 then it will get installed in /usr/local/software/mailStripper-2.1 with its modules installed in /usr/local/software/mailStripper-2.1/lib/perl5 and in subdirectories as appropriate. This means that I have to tell the individual scripts for that application where to find its modules. One of many ways of doing this of course is:
    use lib qq(/usr/local/software/mailStripper-2.1/lib/perl5);
    The weakness of doing that keep in mind is that if I change the version of the application and it gets installed somewhere else I have to make sure I update the use line as appropriate.

    Still local, but I don't want to mix it into Perl's installation directory

    Still keeping in mind the scheme we are using for installing third party software there are cases where I want to make locally developed modules available to multiple applications. We will install those in a directory /usr/local/software/lib/perl5. Again you need to do the use lib ... thing in scripts using those modules.

    Put in with the rest of the modules!

    If you really insist on not dealing with putting use lib... in your scripts to get to your modules then you can always do a
    perl -e "print join($/,@INC);"
    and see where Perl expects to find modules and put your stuff in there. The burden you now have is to keep track of what you put there in the event you upgrade Perl and have to re-install your modules.

    TIAMTOWTDI in Perl...


    Peter L. Berghold -- Unix Professional
    Peter at Berghold dot Net
       Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.
      I would suggest setting the environment variable PERL5LIB externally to running perl scripts, rather than hacking every script to add a use lib. This is considerably less maintenance if you decide to change your directory structure - like upgrading a version.
      The burden you now have is to keep track of what you put there in the event you upgrade Perl and have to re-install your modules.
      There's even a way round this. If you install to a common directory, you can share modules between perl versions:
      perl Makefile.PL LIB=$MYSHARE/lib PREFIX=$MYSHARE make make test make install
      Note that $MYSHARE is a shell environment variable pointing to a path to which you as installer have write access. This even means that you can set up modules without needing root or sysadmin rights.

      To use said directory, set PERL5LIB to include $MYSHARE in the path. It also makes installation possible to other nodes without invoking perl (just tar up the directory and distribute it).

      I tend to specify both LIB and PREFIX because for the following reasons: LIB is specified so that all .pm and XS code can be found. PREFIX is specified to provide placeholders for manpages and any other collateral that does not end up in the LIB. Note: you might get problems between perl versions if you have incompatible XS binaries.

      --
      I'm Not Just Another Perl Hacker

Re: Where to install my own perl modules?
by strat (Canon) on Mar 29, 2004 at 11:48 UTC
    If you create your module templates with h2xs:
    h2xs -A -X -n MyModule
    and fill in the functionality and bundle it with
    perl Makefile.PL make make test make tardist
    you'll get a Module in the form CPAN provides it. And you can easily install it into your own directory (and should do it for development, because with more complex modules it is not so easy to wipe this module out if you want to remove it, whereas you just delete an own directory; the important command is the PREFIX-Option at perl Makefile.PL) with
    tar xvfz modulename.tar.gz cd modulename perl Makefile.PL PREFIX=/path/to/own/modules make make test make install
    In your perl-scripts, just load it by
    use lib qw(/path/to/own/modules) use MyModule;
    but you could as well use any other solution described on this page (e.g. $ENV{PERL5LIB},...)

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Re: Where to install my own perl modules?
by bcrowell2 (Friar) on Mar 29, 2004 at 03:01 UTC
    I've wondered the same thing. I tend to do something like this in my makefile:
    SOURCE_DIR = `perl -e 'use Config; print $$Config{sitelib}'`/foo #... e.g., /usr/local/lib/perl5/site_perl/5.8.0/foo install: $(INSTALL_PROGRAM) -d $(SOURCE_DIR) $(INSTALL_PROGRAM) $(PERL_SOURCES) $(SOURCE_DIR)
    Not sure if this is the best thing to do on all systems -- I run FreeBSD.
Re: Where to install my own perl modules?
by stonecolddevin (Parson) on Mar 29, 2004 at 09:54 UTC
    I recommend use lib qw[path_to_file];
    That way, you can have it in a local directory:
    use lib '.'; use MyModule;
    Or any where else you want it:
    use lib '/home/dhoss/public_html/lib'; use MyModule;
    All posts are spawns of an archaeic and instinctual remnant of pre-neanderthalian neural synapse that, while irrevocably human, remains an anomoly to the common laws of nature.