简体   繁体   English

如何在不使用 CPAN.pm 的情况下安装 Perl 模块?

[英]How can I install Perl module without using CPAN.pm?

Is it possible?可能吗?

If you download the source code, and read the README file.如果您下载了源代码,并阅读了README文件。 This will probably tell you you should do这可能会告诉你你应该做的

perl Makefile.PL
make
make test
make install

or要么

perl Build.PL
./Build
./Build test
./Build install

If you download the source code, it will generally have a Makefile.PL.如果下载源码,一般会有一个Makefile.PL。 You run "perl Makefile.PL; make; make test; make install" and it will build and install for you.你运行“perl Makefile.PL; make; make test; make install”,它会为你构建和安装。

Obviously if you're not using CPAN.pm, you're going to have to deal with dependencies yourself.显然,如果您不使用 CPAN.pm,您将不得不自己处理依赖项。

Also, if the reason you can't use CPAN.pm is that you don't have permission to install into /usr/lib/perl, you can force CPAN.pm to install locally, but I forget how.另外,如果你不能使用 CPAN.pm 的原因是你没有安装到 /usr/lib/perl 的权限,你可以强制 CPAN.pm 在本地安装,但我忘记了如何安装。

If you are on a Linux box, a very large portion of the packages can usually be obtained using the built in package manager.如果您在 Linux 盒子上,通常可以使用内置的 package 管理器获得很大一部分包。 For instance, on an Ubuntu system, if you want to install the PostgreSQL Perl module you'd simple do:例如,在 Ubuntu 系统上,如果您想安装 PostgreSQL Perl 模块,您只需执行以下操作:

sudo apt-get install libpg-perl

You can see a list of the modules for Ubuntu here: http://packages.ubuntu.com/hardy/perl/您可以在此处查看 Ubuntu 的模块列表: http://packages.ubuntu.com/hardy/perl/

I find I can often guess at the names myself.我发现我经常可以自己猜出这些名字。 Not sure if this helps at all, but for myself I often find this easier to use than CPAN as it does a lot better at resolving dependencies.不确定这是否有帮助,但对我自己来说,我经常发现它比 CPAN 更容易使用,因为它在解决依赖关系方面做得更好。

See here: How to install perl modules using CPAN without root参见此处: How to install perl modules using CPAN without root

I have just set this up on a server without root access and CPAN does everything automatically.我刚刚在没有 root 访问权限的服务器上设置了它,CPAN 会自动完成所有操作。

But if you really wanna install a module without CPAN and you don't have root (assuming this since you don't wanna use CPAN), you can do it as follows但是如果你真的想安装一个没有 CPAN 的模块并且你没有 root 权限(假设这是因为你不想使用 CPAN),你可以按如下方式进行

perl Makefile.PL PREFIX=$HOME
make
make install

You're gonna have to hunt down dependencies yourself so it's better to use CPAN.您将不得不自己寻找依赖项,因此最好使用 CPAN。

If the problem is no root access, I would recommend looking at local::lib and also this webpage for CPAN.pm and non-root installation.如果问题是没有 root 访问权限,我建议查看local::lib以及此网页以了解 CPAN.pm 和非 root 安装。

But to answer the question as asked, CPAN or CPANPLUS are helpful, but they aren't required.但是要回答问题,CPAN 或 CPANPLUS 是有帮助的,但不是必需的。 You can always do it the old-fashioned way as Leon says - though usually, it's easier not to.你总是可以像 Leon 所说的那样用老式的方法来做——尽管通常情况下,不这样做会更容易。

If the.pm file is pure Perl and doesn't need to be compiled you can just put it in your application's lib folder and use it as normal.如果 .pm 文件是纯 Perl 并且不需要编译,您可以将它放在应用程序的 lib 文件夹中并正常使用它。

If you are using Red Hat (Fedora, CentOS), you should use RPM for Perl dependencies wherever possible.如果您使用的是 Red Hat(Fedora、CentOS),则应尽可能为 Perl 依赖项使用 RPM。 Perl packages are almost always named perl-Module-Name, eg perl-DBI, perl-Spreadsheet-WriteExcel, etc. Perl 包几乎总是命名为 perl-Module-Name,例如 perl-DBI、perl-Spreadsheet-WriteExcel 等。

On Ubuntu the naming scheme is libmodule-name-perl.在 Ubuntu 上,命名方案是 libmodule-name-perl。

We can install all perl modules both from and even with your terminal in ubuntu. If you are using a ubuntu server then execute the following command, 'sudo apt-get install "perl_module"' The modules which you want just give the name in "perl_module" means If you want to install Apache2::Cookie it will be in "libapreq2" so you have to give like, "sudo apt-get install libapreq2"我们可以通过 ubuntu 中的终端安装所有 perl 模块。如果您使用的是 ubuntu 服务器,则执行以下命令,'sudo apt-get install "perl_module"' 您想要的模块只需在“ perl_module" 意味着如果你想安装 Apache2::Cookie 它将在 "libapreq2" 中,所以你必须像 "sudo apt-get install libapreq2"

If you're asking this because you're having problems with CPAN... you're probably running out of RAM that's why you can't use CPAN.如果你问这个是因为你在使用 CPAN 时遇到问题......你可能已经用完了 RAM,这就是你不能使用 CPAN 的原因。

Maybe you don't have a swap file.也许您没有交换文件。 Try this:试试这个:

$ sudo su
# dd if=/dev/zero of=/swap bs=1M count=1k # create a 1GB file
# mkswap /swap
# swapon /swap

Otherwise... stop some services.否则......停止一些服务。

$ sudo service mysql stop
$ sudo service nginx stop

...And try again ...然后再试一次

$ cpan install CPAN
$ cpan install MIME::Lite::TT::HTML

I, as others have would highly suggest using CPAN.pm.我和其他人一样强烈建议使用 CPAN.pm。 It is a breeze to use and can resolve any dependencies associated with the module you need automatically.使用起来轻而易举,并且可以自动解决与您需要的模块相关的任何依赖关系。

On the other hand, I would suggest that you read the perlmodinstall document over at perldoc as it gives details on other os' as well.另一方面,我建议您阅读perldoc上的perlmodinstall文档,因为它也提供了其他操作系统的详细信息。

Regards,问候,

Jeff杰夫

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM