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

I am a user of a Linux box whose sysadmin policy is benign neglect. I can install and run anything I need, provided I can run it in my home directory.

I can't user perl -MCPAN in its usual configuration, because I can't write to the directories in @INC. Is there a way to install a module in a subdir of $HOME, and then update @INC at runtime to point to those modules? tia, -clay

  • Comment on Using CPAN to install modules in $HOME?

Replies are listed 'Best First'.
Re: Using CPAN to install modules in $HOME?
by Zaxo (Archbishop) on Feb 21, 2002 at 14:57 UTC

    perldoc CPAN has a FAQ section. Item 1 answers your question.

    Update: ++Chmrr has pointed out that this is FAQ #5 in the Perl 5.6.1 distribution version. YMMV depending on your local version of perl and CPAN.pm. ExtUtils::MakeMaker has a more complete list of the installation directories you can set. Use your local perldoc to get the most accurate info on your installed modules.

    After Compline,
    Zaxo

Re: Using CPAN to install modules in $HOME?
by ehdonhon (Curate) on Feb 21, 2002 at 21:04 UTC

    Yes, you can do this by creating a file named $HOME/.cpan/CPAN/MyConfig.pm In that file, you can specify custom arguments to be added any time that a Makefille.PL is run. By specifying a LIB= or PREFIX= argument, you can make the CPAN module install the lib any place you want. It would look something like this:

    $CPAN::Config->{makepl_arg} = q[ PREFIX=DIRECTORY_NAME ];

    Or, if you are working with the interactive shell, you can just skip the config file, and do this from the shell:

    o conf makepl_arg PREFIX=DIRECTORY_NAME
    
    (where DIRECTORY_NAME is the name of the directory you wish to install to).

    Good luck!

      Being a non-root user I have tried doing this (installing modules into a directory for which I have write permission), and then adding the directory into @INC with

      use lib '/path/to/my/dir';

      but this doesn't work with modules for which an older version exists. Perl uses the older version (DBI v1.13 instead of DBI v1.30). Is there a way I can specify the version/location I want used instead of letting Perl pick the one it likes? Or, I guess more specifically, can I specify explicitly the order in which directories containing libraries should be considered for inclusion.

      UPDATE: Just in case anyone else should ever have this problem, I found out there are multiple instances of perl installed on our system. The default instance called when I ran  perl Makefile.pl  is in a different location than the one I specified in my script. It solved the problem to re-install the module using  /path/to/perl Makefile.pl  when compiling the module.

        Perl should always search for libraries in your directories in the order that they appear in @INC. If '/path/to/my/dir' is the first thing in @INC, perl will look there first.

        You might want to try something like this:

        #!/usr/bin/perl use lib '/path/to/my/dir'; use DBI; use Data::Dumper; print Dumper( \@INC, \%INC );

        That will tell you exactly what is in your @INC, and exactly where Perl is finding all its libraries.