• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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人参与评论

请发表评论

全部评论

专题导读
上一篇:
Perl——哈希的创建和引用发布时间:2022-07-22
下一篇:
perl shell脚本互调发布时间:2022-07-22
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap