I am using Perl running in user space (not installed via root) and installing modules via the command-line cpan
. I would like to know if there is a simple way to remove a module without having to do a lot of work deleting individual files.
我正在使用Perl在用户空间中运行(不是通过root安装)并通过命令行cpan安装模块。我想知道是否有一种简单的方法来删除模块而无需删除单个文件。
I searched for this question on the internet and found some answers, but the answers I've found seem to either discuss using the Perl package manager (specific for Microsoft Windows), otherwise operating-system specific (BSDpan), suggesting using cpanplus (which I've had several bad experiences with), or ended by pointing to a dead link as follows: http://www.cpan.org/misc/cpan-faq.html#How_delete_Perl_modules
.
我在互联网上搜索了这个问题,并找到了一些答案,但我发现的答案似乎要么使用Perl软件包管理器(特定于Microsoft Windows),否则特定于操作系统(BSDpan),建议使用cpanplus(其中)我有几次糟糕的经历,或者通过指向死链接结束如下:http://www.cpan.org/misc/cpan-faq.html#How_delete_Perl_modules。
My question is specifically whether there is a clean way to remove a module installed via cpan
.
我的问题是具体是否有一种干净的方法来删除通过cpan安装的模块。
6 个解决方案
#1
36
You can't. There isn't a feature in my CPAN client to do such a thing. We were talking about how we might do something like that at this weekend's Perl QA Workshop, but it's generally hard for all the reasons that Ether mentioned.
你不能。我的CPAN客户端中没有功能可以执行此类操作。在本周末的Perl QA研讨会上,我们讨论的是我们如何做这样的事情,但以太提到的所有原因通常很难。
#2
29
As a general rule, there is not a specific 'uninstall' mechanism that comes with CPAN modules. But you might try make uninstall
in the original directory the module unpacked into (this is often under /root/.cpan
or ~/.cpan
), as some packages do contain this directive in their install script. (However, since you've installed modules into a local (non-root) library directory, you also have the option of blowing away this entire directory and reinstalling everything else that you want to keep.)
作为一般规则,CPAN模块没有特定的“卸载”机制。但您可以尝试在模块解压缩到的原始目录中进行卸载(这通常位于/root/.cpan或〜/ .cpan下),因为某些软件包在其安装脚本中包含此指令。 (但是,由于您已将模块安装到本地(非根)库目录中,因此您还可以选择清除整个目录并重新安装要保留的所有其他目录。)
A lot of the time you can simply get away with removing the A/B.pm
file (for the A::B
module) from your perllib -- that will at least render the module unusable. Most modules also contain a list of files to be installed (called a "manifest"), so if you can find that, you'll know which files you can delete.
很多时候你可以简单地从你的perllib中删除A / B.pm文件(对于A :: B模块) - 这至少会使模块无法使用。大多数模块还包含要安装的文件列表(称为“清单”),因此如果您能找到它,您将知道可以删除哪些文件。
However, none of these approaches will address any modules that were installed as dependencies. There's no good (automated) way of knowing if something else is dependent on that module, so you'll have to uninstall it manually as well once you're sure.
但是,这些方法都不会解决任何作为依赖项安装的模块。没有好的(自动的)方式来了解其他东西是否依赖于该模块,所以一旦你确定,你也必须手动卸载它。
The difficulty in uninstalling modules is one reason why many Perl developers are moving towards using a revision control system to keep track of installations -- e.g. see the article by brian d foy as a supplement to his upcoming book that discusses using git for package management.
卸载模块的困难是许多Perl开发人员正在转向使用修订控制系统来跟踪安装的一个原因 - 例如请参阅brian d foy的文章作为他即将出版的书籍的补充,该书讨论了如何使用git进行包管理。
#3
28
- Install
App::cpanminus
from CPAN (use:cpan App::cpanminus
for this). - 从CPAN安装App :: cpanminus(使用:cpan App :: cpanminus)。
- Type
cpanm --uninstall Module::Name
(note the "m
") to uninstall the module with cpanminus. - 键入cpanm --uninstall Module :: Name(注意“m”)以使用cpanminus卸载模块。
This should work.
这应该工作。
#4
22
There are scripts on CPAN which attempt to uninstall modules:
CPAN上有脚本试图卸载模块:
- pm-uninstall
- PM-卸载
- perlrocks
- perlrocks
ExtUtils::Packlist shows sample module removing code, modrm
.
ExtUtils :: Packlist显示示例模块删除代码modrm。
#5
16
Update 2013: This code is obsolescent. Upvote bsb's late-coming answer instead.
更新2013:此代码已过时。请改用bsb迟到的答案。
I don't need to uninstall modules often, but the .packlist
file based approach has never failed me so far.
我不需要经常卸载模块,但基于.packlist文件的方法到目前为止从未让我失望过。
use 5.010;
use ExtUtils::Installed qw();
use ExtUtils::Packlist qw();
die "Usage: $0 Module::Name Module::Name\n" unless @ARGV;
for my $mod (@ARGV) {
my $inst = ExtUtils::Installed->new;
foreach my $item (sort($inst->files($mod))) {
say "removing $item";
unlink $item or warn "could not remove $item: $!\n";
}
my $packfile = $inst->packlist($mod)->packlist_file;
print "removing $packfile\n";
unlink $packfile or warn "could not remove $packfile: $!\n";
}
#6
2
Since at the time of installing of any module it mainly put corresponding .pm files in respective directories. So if you want to remove module only for some testing purpose or temporarily best is to find the path where module is stored using perldoc -l <MODULE>
and then simply move the module from there to some other location. This approach can also be tried as a more permanent solution but i am not aware of any negative consequences as i do it mainly for testing.
由于在安装任何模块时,它主要将相应的.pm文件放在各自的目录中。因此,如果您只想为某些测试目的删除模块,或者暂时最好是使用perldoc -l <MODULE>找到存储模块的路径,然后只需将模块从那里移动到其他位置。这种方法也可以尝试作为一种更持久的解决方案,但我不知道任何负面后果,因为我主要是为了测试。
#1
36
You can't. There isn't a feature in my CPAN client to do such a thing. We were talking about how we might do something like that at this weekend's Perl QA Workshop, but it's generally hard for all the reasons that Ether mentioned.
你不能。我的CPAN客户端中没有功能可以执行此类操作。在本周末的Perl QA研讨会上,我们讨论的是我们如何做这样的事情,但以太提到的所有原因通常很难。
#2
29
As a general rule, there is not a specific 'uninstall' mechanism that comes with CPAN modules. But you might try make uninstall
in the original directory the module unpacked into (this is often under /root/.cpan
or ~/.cpan
), as some packages do contain this directive in their install script. (However, since you've installed modules into a local (non-root) library directory, you also have the option of blowing away this entire directory and reinstalling everything else that you want to keep.)
作为一般规则,CPAN模块没有特定的“卸载”机制。但您可以尝试在模块解压缩到的原始目录中进行卸载(这通常位于/root/.cpan或〜/ .cpan下),因为某些软件包在其安装脚本中包含此指令。 (但是,由于您已将模块安装到本地(非根)库目录中,因此您还可以选择清除整个目录并重新安装要保留的所有其他目录。)
A lot of the time you can simply get away with removing the A/B.pm
file (for the A::B
module) from your perllib -- that will at least render the module unusable. Most modules also contain a list of files to be installed (called a "manifest"), so if you can find that, you'll know which files you can delete.
很多时候你可以简单地从你的perllib中删除A / B.pm文件(对于A :: B模块) - 这至少会使模块无法使用。大多数模块还包含要安装的文件列表(称为“清单”),因此如果您能找到它,您将知道可以删除哪些文件。
However, none of these approaches will address any modules that were installed as dependencies. There's no good (automated) way of knowing if something else is dependent on that module, so you'll have to uninstall it manually as well once you're sure.
但是,这些方法都不会解决任何作为依赖项安装的模块。没有好的(自动的)方式来了解其他东西是否依赖于该模块,所以一旦你确定,你也必须手动卸载它。
The difficulty in uninstalling modules is one reason why many Perl developers are moving towards using a revision control system to keep track of installations -- e.g. see the article by brian d foy as a supplement to his upcoming book that discusses using git for package management.
卸载模块的困难是许多Perl开发人员正在转向使用修订控制系统来跟踪安装的一个原因 - 例如请参阅brian d foy的文章作为他即将出版的书籍的补充,该书讨论了如何使用git进行包管理。
#3
28
- Install
App::cpanminus
from CPAN (use:cpan App::cpanminus
for this). - 从CPAN安装App :: cpanminus(使用:cpan App :: cpanminus)。
- Type
cpanm --uninstall Module::Name
(note the "m
") to uninstall the module with cpanminus. - 键入cpanm --uninstall Module :: Name(注意“m”)以使用cpanminus卸载模块。
This should work.
这应该工作。
#4
22
There are scripts on CPAN which attempt to uninstall modules:
CPAN上有脚本试图卸载模块:
- pm-uninstall
- PM-卸载
- perlrocks
- perlrocks
ExtUtils::Packlist shows sample module removing code, modrm
.
ExtUtils :: Packlist显示示例模块删除代码modrm。
#5
16
Update 2013: This code is obsolescent. Upvote bsb's late-coming answer instead.
更新2013:此代码已过时。请改用bsb迟到的答案。
I don't need to uninstall modules often, but the .packlist
file based approach has never failed me so far.
我不需要经常卸载模块,但基于.packlist文件的方法到目前为止从未让我失望过。
use 5.010;
use ExtUtils::Installed qw();
use ExtUtils::Packlist qw();
die "Usage: $0 Module::Name Module::Name\n" unless @ARGV;
for my $mod (@ARGV) {
my $inst = ExtUtils::Installed->new;
foreach my $item (sort($inst->files($mod))) {
say "removing $item";
unlink $item or warn "could not remove $item: $!\n";
}
my $packfile = $inst->packlist($mod)->packlist_file;
print "removing $packfile\n";
unlink $packfile or warn "could not remove $packfile: $!\n";
}
#6
2
Since at the time of installing of any module it mainly put corresponding .pm files in respective directories. So if you want to remove module only for some testing purpose or temporarily best is to find the path where module is stored using perldoc -l <MODULE>
and then simply move the module from there to some other location. This approach can also be tried as a more permanent solution but i am not aware of any negative consequences as i do it mainly for testing.
由于在安装任何模块时,它主要将相应的.pm文件放在各自的目录中。因此,如果您只想为某些测试目的删除模块,或者暂时最好是使用perldoc -l <MODULE>找到存储模块的路径,然后只需将模块从那里移动到其他位置。这种方法也可以尝试作为一种更持久的解决方案,但我不知道任何负面后果,因为我主要是为了测试。