2010年12月20日星期一

非root用户通过cpan安装perl模块

任何用户都可以通过cpan安装模块。root用户在配置cpan时,基本采用默认配置就可以。根据默认配置,perl模块将被安装在系统目录(比如:/usr/lib/perl5/site_perl/5.8.8)。但非root用户在配置cpan的时候,如果也采用上述办法,则配置cpan完毕后,极有可能会由于对/usr/lib/perl5/site_perl/5.8.8没有写入权限而导致无法安装模块。对于这个问题,可以通过在配置cpan时修改模块安装的PREFIX来解决。具体方法如下,当在配置cpan出现下面的提示时:

Every Makefile.PL is run by perl in a separate process. Likewise we
run 'make' and 'make install' in processes. If you have any
parameters (e.g. PREFIX, LIB, UNINST or the like) you want to pass
to the calls, please specify them here.

If you don't understand this question, just press ENTER.

Parameters for the 'perl Makefile.PL' command?
Typical frequently used settings:

PREFIX=~/perl non-root users (please see manual for more hints)

Your choice: []

此时如果用户是root,且打算将模块安装在系统目录下供所有用户使用,则直接输入回车。如果是非root用户,此时只要根据提示内容,简单输入:PREFIX=~/perl 即可。这样该用户perl模块的安装目录将更改为~/perl。在写程序时,只要将该目录加入到@INC列表,即可正常使用。

安装任何软件的时候都一定要注意看提示啊!

没有评论:

发表评论