删除使用 cpanm 安装的 perl 模块

删除使用 cpanm 安装的 perl 模块

我是 Perl 初学者。我想使用 Log::Log4perl 模块,因为我熟悉它在 Java 中的工作方式。我使用 cpanm 脚本下载模块,但我没有使用“sudo”运行它。然后它将此模块安装到我的目录 /home/amer/perl5。之后,我将其安装为 sudoer,但我想删除主目录中的安装以避免将来发生任何冲突。我该怎么做? 这是我的命令行执行堆栈。

感谢致敬!

答案1

目前,这还处于实验阶段,但现在 cpanm 支持卸载选项。从元Cpan

-U,--卸载

实验:卸载模块。将使用 .packlist 文件从库路径中删除分发文件。与 -l 或 -L 一起使用时,只会删除 local::lib 目录下的文件。注意:如果您在多个位置(即 site_perl 和 perl 库路径,使用 perl 5.12 或更高版本)都有“dual-life”模块,则只会删除 site_perl 中的文件。如果分发版有 bin 脚本和 man,它们将被保留,以防核心安装仍然引用它们,尽管不能保证脚本将继续按预期与旧版本的 .pm 文件一起工作。

答案2

尝试应用程序::pmuninstall

描述

App::pmuninstall 是一个快速模块卸载程序。从 .packlist 中删除文件。

App::cpanminus 和 App::cpanoutdated 具有很高的亲和力。

答案3

从您的用户帐户进入 shell/命令提示符,输入百万分之一英寸。当 PPM 打开时输入“remove [package name]”,这将为您卸载该特定包。在 PPM 中输入“help remove”以获取更多详细信息。

答案4

我用了大卫·法雷尔的剧本

#!/usr/bin/perl
# uninstall_perl_module.pl from PerlTricks.com

use 5.14.2;
use ExtUtils::Installed;
use ExtUtils::Packlist;

# Exit unless a module name was passed
die ("Error: no Module::Name passed as an argument. E.G.\n\t perl $0 Module::Name\n") unless $#ARGV == 0;

my $module = shift @ARGV;

my $installed_modules = ExtUtils::Installed->new;

# iterate through and try to delete every file associated with the module
foreach my $file ($installed_modules->files($module)) {
    print "removing $file\n";
    unlink $file or warn "could not remove $file: $!\n";
}

# delete the module packfile
my $packfile = $installed_modules->packlist($module)->packlist_file;
print "removing $packfile\n";
unlink $packfile or warn "could not remove $packfile: $!\n";

# delete the module directories if they are empty
foreach my $dir (sort($installed_modules->directory_tree($module))) {
    print("removing $dir\n");
    rmdir $dir or warn "could not remove $dir: $!\n";
}

尽管它产生了一些看起来很吓人的输出,但它还是完成了工作:-):

removing /
could not remove /: Device or resource busy
removing /home
could not remove /home: Permission denied

你可能还想看看这个帖子

相关内容