perl下安裝模塊可以使用cpan命令,但是通常我們不具有root用戶權限,所以只能以sudo方式安裝模塊。
例如需要安裝Net::SCP::Expect模塊,
執行cpan Net::SCP::Expect
首次使用cpan命令會出現 choice local or sudo的樣式,默認為local,建議使用sudo.
最后會出現
ERROR: Can't create '/usr/local/man/man3' Do not have write permissions on '/usr/local/man/man3' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! at -e line 1. Makefile:706: recipe for target 'pure_site_install' failed make: *** [pure_site_install] Error 13 RYBSKEJ/Net-SCP-Expect-0.16.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'
由於非root用戶無法在/usr/local目錄下進行操作。
執行sudo cpan Net::SCP::Expect
即可正常安裝模塊。
未安裝cpan
[root@idip bin]# cpan Recursive bash: cpan: 未找到命令... [root@idip bin]# ppm install File::Copy::Recursive bash: ppm: 未找到命令... [root@idip bin]# sudo perl -MCPAN -e shell Can't locate CPAN.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .). BEGIN failed--compilation aborted. [root@idip bin]# yum -y install perl-CPAN 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com
參考:查看安裝的perl模塊版本的方法
手動查詢的方法
查詢path: perldoc -l $1
查詢版本: perl -M$1 -e 'print $1->VERSION. "\n"'
一個例子:
[root@atlas73 ~]# perl -MConfig::IniFiles -e 'print Config::IniFiles->VERSION. "\n"'
沒安裝此模塊,則輸出如下
Can't locate Config/IniFiles.pm in @INC (you may need to install the Config::IniFiles module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.2 /usr/local/share/perl/5.22.2 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .). BEGIN failed--compilation aborted.
另一個例子
[root@atlas73 ~]$ perl -MNet::SCP::Expect -e 'print Net::SCP::Expect->VERSION. "\n"'
已安裝此模塊,輸出版本號:
0.16
2.66
刪除已安裝的模塊:
使用App::pmunintsall模塊來實現:cpan>install App::pmuninstall
安裝完成后,退出cpan
執行刪除模塊操作:cmd>pm-uninstall DBD::Oracle