经常写一些perl程序,放到cluster服务器上就没办法运行,因为它需要root权限安装一些模块(modules),而显然我是不可能拥有root权限的。怎么办呢?幸运的是,有一个模块叫做local::lib,可以完全绕过root权限。
local::lib简介
local::lib是一个可以让你将perl模块安装在用户HOME目录下的perl模块。无需root权限。当然别人是无法使用你自己安装的perl模块的。local::lib本身自然也是不需要root权限的。
local::lib的安装
首先去http://search.cpan.org/dist/local-lib下载最新版的local::lib。
然后在一个terminal内将其解压:
cd Downloads tar -xzf local-lib-1.00xxxxxx.tar.gz cd local-lib-1.00xxxxxx |
下一步,将local::lib加入至bootstrap当中去。这一步会在用户HOME目录下新建一个perl5的目录,并且指定它为将来安装perl模块的目录。
perl Makefile.PL --bootstrap |
而后安装local::lib
make make test make install |
而后试运行一下perl
perl -MCPAN -eshell |
一路选择默认值,然后退出。这一步,perl会将本地的模块搜索目录放入至.bashrc文件尾部。
安装其它perl模块
这个时候我们就可以进行非root权限的perl模块安装了。我们首先需要从先前的terminal窗口中退出来,重开一个terminal窗口,这样就会过一遍.bashrc文件。试着安装一个模块,
perl -MCPAN -eshell nolock_cpan[1]> install File::ReadBackwards |
一切OK。
为cluster扩展library path
可以简单的在qsub文件中运行perl之前加入PERL5LIB的搜索路径
echo $PERL5LIB |
然后将传回的值写入qsub当中去
PERL5LIB=/home/path/lib:/usr/another/path/lib; export PERL5LIB |
也可在执行命令中加入-I参数
perl -I /home/path/lib -I /usr/another/lib script.pl |
或者在pl文件头里加入lib的路径
#!/usr/bin/perl use lib "/home/path/lib"; use lib "/usr/another/lib"; use MyCustomModule; |
但是我试运行Perl的时候,终端显示:终端不支持AddHistory. 请问这是怎么回事,我应该怎么解决呢?
谢谢!
检查你的Term::ReadLine module安装是否正确。
LZ你好,在运行了make install之后报错
Can’t create ‘/usr/local/share/man/man3’
Do not have write permissions on ‘/usr/local/share/man/man3’
你当前的工作目录是什么?查看读写权限。最好是换个目录操作。
找到原因了 在bash里面加这么一段就行
/bin/csh
echo $SHELL
/bin/csh
echo ‘eval `perl -I$HOME/perl5/lib/perl5 -Mlocal::lib`’ >> ~/.cshrc
谢谢分享。
我的工作目录是有读写权限的。
我觉得既然perl Makefile.PL –bootstrap这一步已经指定以后perl模块安装在$HOME/perl5里面,
就不应该再create ‘/usr/local/share/man/man3 这种事情了把?为啥还要往这个文件里面写入?我们没有/usr/local的权限
LZ你说换个目录操作是指的。。?我安装local:lib是成功了的,之后我还是在这个目录试着安装一下别的模块,就报错了。。我想知道这个create ‘/usr/local/share/man/man3能不能改到我有权限的地方啊?
报错如下:
Manifying blib/man3/File::ReadBackwards.3pm
URI/File-ReadBackwards-1.05.tar.gz
/usr/bin/make — OK
Warning (usually harmless): ‘YAML’ not installed, will not store persistent state
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl “-MExtUtils::Command::MM” “-e” “test_harness(0, ‘blib/lib’, ‘blib/arch’)” t/*.t
t/bw.t ………. ok
t/large_file.t .. ok
All tests successful.
Files=2, Tests=173, 2 wallclock secs ( 0.07 usr 0.02 sys + 1.72 cusr 0.11 csys = 1.92 CPU)
Result: PASS
URI/File-ReadBackwards-1.05.tar.gz
/usr/bin/make test — OK
Warning (usually harmless): ‘YAML’ not installed, will not store persistent state
Running make install
Prepending /lustre/home/clswcc/.cpan/build/File-ReadBackwards-1.05-A03jJ_/blib/arch /lustre/home/clswcc/.cpan/build/File-ReadBackwards-1.05-A03jJ_/blib/lib to PERL5LIB for ‘install’
Manifying blib/man3/File::ReadBackwards.3pm
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: Can’t create ‘/usr/local/share/man/man3’
Do not have write permissions on ‘/usr/local/share/man/man3’
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
at -e line 1
make: *** [pure_site_install] Error 13
URI/File-ReadBackwards-1.05.tar.gz
/usr/bin/make install — NOT OK
—-
You may have to su to root to install the package
(Or you may want to run something like
o conf make_install_make_command ‘sudo make’
to raise your permissions.Warning (usually harmless): ‘YAML’ not installed, will not store persistent state
Failed during this command:
URI/File-ReadBackwards-1.05.tar.gz : install NO
请问,mkl,你的解决方法,在bash里加上
/bin/csh
echo $SHELL
/bin/csh
echo ‘eval `perl -I$HOME/perl5/lib/perl5 -Mlocal::lib`’ >> ~/.cshrc
这个是怎么加的呢
你有home目录下有没有.cshrc这个文件?