perl安装模块到自己的home ( install perl module without root)

use local::lib to install perl modules in your home directory ?

https://metacpan.org/pod/local::lib + http://search.cpan.org/ 
By default local::lib installs itself and the CPAN modules into ~/perl5.
Windows users must also see "Differences when using this module under Win32".

  1. Download and unpack the local::lib tarball from CPAN (search for "Download" on the CPAN page about local::lib). Do this as an ordinary user, not as root or administrator. Unpack the file in your home directory or in any other convenient location.

  2. Run this:

      perl Makefile.PL --bootstrap

    If the system asks you whether it should automatically configure as much as possible, you would typically answer yes.

    In order to install local::lib into a directory other than the default, you need to specify the name of the directory when you call bootstrap, as follows:

      perl Makefile.PL --bootstrap=~/foo
  3. Run this: (local::lib assumes you have make installed on your system)

      make test && make install
  4. Now we need to setup the appropriate environment variables, so that Perl starts using our newly generated lib/ directory. If you are using bash or any other Bourne shells, you can add this to your shell startup script this way:

      echo '[ $SHLVL -eq 1 ] && eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >>~/.bashrc

    If you are using C shell, you can do this as follows:

      /bin/csh
      echo $SHELL
      /bin/csh
      echo 'eval `perl -I$HOME/perl5/lib/perl5 -Mlocal::lib`' >> ~/.cshrc

    If you passed to bootstrap a directory other than default, you also need to give that as import parameter to the call of the local::lib module like this way:

      echo '[ $SHLVL -eq 1 ] && eval "$(perl -I$HOME/foo/lib/perl5 -Mlocal::lib=$HOME/foo)"' >>~/.bashrc

    After writing your shell configuration file, be sure to re-read it to get the changed settings into your current shell's environment. Bourne shells use . ~/.bashrc for this, whereas C shells use source ~/.cshrc.

 

http://learn.perl.org/faq/perlfaq8.html

How do I keep my own module/library directory?

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

If you want to install modules for your own use, the easiest way might be local::libexternal link, which you can download from CPAN. It sets various installation settings for you, and uses those same settings within your programs.

If you want more flexibility, you need to configure your CPAN client for your particular situation.

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 mbuild_arg "--install_base /mydir/perl"
    cpan> o conf commit

INSTALL_BASE tells these tools to put your modules into /mydir/perl/lib/perl5. See "How do I add a directory to my include path (@INC) at runtime?" for details on how to run your newly installed modules.

There is one caveat with INSTALL_BASE, though, since it acts differently from the PREFIX and LIB settings that older versions of ExtUtils::MakeMakerexternal link advocated. INSTALL_BASE does not support installing modules for multiple versions of Perl or different architectures under the same directory. You should consider whether you really want that and, if you do, use the older PREFIX and LIB settings. See the ExtUtils::Makemakerexternal link documentation for more details.

 

How do I add a directory to my include path (@INC) at runtime?

Here are the suggested ways of modifying your include path, including environment variables, run-time switches, and in-code statements:

the PERLLIB environment variable
    $ export PERLLIB=/path/to/my/dir
    $ perl program.pl
the PERL5LIB environment variable
    $ export PERL5LIB=/path/to/my/dir
    $ perl program.pl
the perl -Idir command line flag
    $ perl -I/path/to/my/dir program.pl
the lib pragma:
    use lib "$ENV{HOME}/myown_perllib";
the local::libexternal link module:
    use local::lib;

    use local::lib "~/myown_perllib";

 

posted @ 2012-03-26 18:44  iTech  阅读(4777)  评论(0编辑  收藏  举报