Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uninstall all perl modules installed by cpan

Tags:

Yesterday I wanted to test some software and in the documentation it said, to install I just needed to type

cpan -i Software 

I never used cpan, I just know that it is the perl package manager. (Is it..?) However, it turned out that I needed loads of dependencies, and stupid as I am, I just installed all of them. (First, I had to set up cpan which asked me lots of questions) Long story short, I just want to remove all of it again. I googled a bit, and it seems like cpan does not have an uninstall routine, especially for all the packages at once. Can I just remove some directory or will I run into troubles?

like image 608
janoliver Avatar asked Oct 15 '11 10:10

janoliver


People also ask

How do I remove a Perl module from CPAN?

Install App::cpanminus from CPAN (use: cpan App::cpanminus for this). Type cpanm --uninstall Module::Name (note the " m ") to uninstall the module with cpanminus.

How do I uninstall CPAN?

To uninstall (if you want to free space) simply delete the ~/. cpan and ~/cpan directories (or other directories if you changed the installation path).

Where are CPAN modules installed?

CPAN doesn't actually install files. It runs the install script embedded in each distribution, which then performs the actual install. For distributions using ExtUtils::MakeMaker, the defaults are documented here: https://metacpan.org/pod/ExtUtils::MakeMaker#make-install (and the default value of INSTALLDIRS is site ).

What is CPAN module in Perl?

The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors.


2 Answers

the cpan command isn't really a package manager like apt-get is. It is more a tool that downloads and installs from CPAN (the site, or one of its mirrors). After it has finished this task it doesn't remember much about what was done before, at least not enough to remove previously installed modules, at least not reliably, cleanly or dependency-safely. (Update: After looking at App::pmuninstall, it can be used to handle dependencies, but it does so by connecting to outside (read: web) sources, which compute these separately, which is fine, but I stand by the previous statement that CPAN.pm doesn't do this.)

I used to worry about removing modules, but now I realize that most Perl modules take up so little room that I just don't worry about having a few extra modules installed that you will never use. So unless you are on a computer with a REALLY small disc, I would just let it be.

On Windows or if you are using a non-system Perl on Linux/Mac you could just remove Perl and reinstall it. I would not recommend this if you are using the system installed Perl on Linux/Mac however as you could break your OS doing this (you might be ok if you were careful, but not worth it to save a few Mb!).

In the future, you can easily install a local version of Perl using perlbrew, there are tutorials all over the web if the docs aren't sufficient (they should be). This also has the bonus of letting you play with the newest and greatest Perl versions, which your system likely doesn't come with yet. Then if you install a mountain of junk, or even break it doing something crazy, remove that version and reinstall/install a different version.

Another nice tool is cpanminus (or cpanm for short) which is a newer, more user friendly cpan tool. All the cool kids are using it.

like image 101
Joel Berger Avatar answered Oct 04 '22 12:10

Joel Berger


You can uninstall individual modules with cpanplus (ships with Perl) like this:

cpanp uninstall SQL::Abstract 

You can view all modules installed with the cpan script like this:

perldoc perllocal 

Putting the two together:

for module in $(perldoc -u perllocal | grep -F 'C<Module> L<' | sed 's/^.*L<\(.*\)|.*>$/\1/') ; do     cpanp uninstall "$module" done 
like image 36
Flimm Avatar answered Oct 04 '22 14:10

Flimm