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::lib, 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::MakeMaker 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::Makemaker 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::lib module:
    use local::lib;

    use local::lib "~/myown_perllib";

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值