How can I install a CPAN module into a local directory?

前端 未结 5 1683
庸人自扰
庸人自扰 2020-11-22 16:17

I\'m using a hosted Linux machine so I don\'t have permissions to write into the /usr/lib directory.

When I try to install a CPAN module by doing the us

相关标签:
5条回答
  • 2020-11-22 16:50

    I strongly recommend Perlbrew. It lets you run multiple versions of Perl, install packages, hack Perl internals if you want to, all regular user permissions.

    0 讨论(0)
  • 2020-11-22 16:51

    local::lib will help you. It will convince "make install" (and "Build install") to install to a directory you can write to, and it will tell perl how to get at those modules.

    In general, if you want to use a module that is in a blib/ directory, you want to say perl -Mblib ... where ... is how you would normally invoke your script.

    0 讨论(0)
  • 2020-11-22 16:56

    Other answers already on Stackoverflow:

    • How do I install modules locally without root access...
    • How can I use a new Perl module without install permissions?

    From perlfaq8:


    How do I keep my own module/library directory?

    When you build modules, tell Perl where to install the modules.

    For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:

    perl Makefile.PL INSTALL_BASE=/mydir/perl
    

    You can set this in your CPAN.pm configuration so modules automatically install in your private library directory when you use the CPAN.pm shell:

    % cpan
    cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl
    cpan> o conf commit
    

    For Build.PL-based distributions, use the --install_base option:

    perl Build.PL --install_base /mydir/perl
    

    You can configure CPAN.pm to automatically use this option too:

    % cpan
    cpan> o conf mbuildpl_arg '--install_base /mydir/perl'
    cpan> o conf commit
    
    0 讨论(0)
  • 2020-11-22 17:06

    I had a similar problem, where I couldn't even install local::lib

    I created an installer that installed the module somewhere relative to the .pl files

    The install goes like:

    perl Makefile.PL PREFIX=./modulos
    make
    make install
    

    Then, in the .pl file that requires the module, which is in ./

    use lib qw(./modulos/share/perl/5.8.8/); # You may need to change this path
    use module::name;
    

    The rest of the files (makefile.pl, module.pm, etc) require no changes.

    You can call the .pl file with just

    perl file.pl
    
    0 讨论(0)
  • 2020-11-22 17:07

    For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:

    perl Makefile.PL INSTALL_BASE=/mydir/perl
    
    0 讨论(0)
提交回复
热议问题