How do I update all my CPAN modules to their latest versions?
5 Answers
An alternative method to using upgrade
from the default CPAN shell is to use cpanminus
and cpan-outdated
.
These are so easy and nimble to use that I hardly ever go back to CPAN shell. To upgrade all of your modules in one go, the command is:
cpan-outdated -p | cpanm
I recommend you install cpanminus
like the docs describe:
curl -L https://cpanmin.us | perl - App::cpanminus
And then install cpan-outdated
along with all other CPAN modules using cpanm
:
cpanm App::cpanoutdated
BTW: If you are using perlbrew
then you will need to repeat this for every Perl you have installed under it.
You can find out more about cpanminus
and cpan-outdated
at the Github repos here:

- 640
- 8
- 20

- 22,441
- 5
- 48
- 71
-
6why using such extra tools while there's a built-in solution (see second answer)? – eav Nov 08 '12 at 08:37
-
4"why using such extra tools" While it's outside the scope of the OP's question, cpanimus DOES solve the problem of CPAN asking you to press Enter and/or type [y]es. Afaict you can not _reliably_ suppress this behavior with vanilla CPAN. This becomes important as soon as any kind of cron or CI server is involved, and/or if you like to be able to start an upgrade with the confidence it won't hang while you're out getting coffee (which in my experience is often the case with vanilla CPAN) See also this answer http://stackoverflow.com/questions/898782/how-do-i-tell-cpan-to-install-all-dependencies – Noah Sussman Dec 27 '13 at 16:33
-
1[root@portal-test bugzilla-4.4.4]# cpan-outdated -p | cpanm Can't locate object method "new" via package "LWP::UserAgent" at /usr/bin/cpan-outdated line 170. – shorif2000 Jun 05 '14 at 11:52
-
@eav Because it's more "nimble"! The built-in solution (CPAN shell) does not work well in limited memory hence why Miyagawa originally developed cpanminus - https://metacpan.org/pod/App::cpanminus#Another-CPAN-installer – draegtun Jun 06 '14 at 10:09
-
@sharif - Need more info... what versions of cpanminus, cpan-outdated, LWP and Perl are you using? – draegtun Jun 06 '14 at 10:10
-
perl v5.8.8. LWP 5.805. centos 5.10 final – shorif2000 Jun 06 '14 at 15:20
-
4Those are old (perl dates from 2006, LWP from 2005). Ideally you need newer version of both. If for some reason you can't do this then I would upgrade LWP version by version until you got cpanm|cpan-outdated working. NB. IMPORTANT - If you are using the CentOS installed Perl then don't use CPAN or CPANMINUS with these! Never mix with OS packages!! Instead use Perlbrew to brew your own perl (and then use cpanminus etc within this). – draegtun Jun 06 '14 at 19:31
-
1I like this solutions because you can easily run `cpan-outdated -p` first to see what it is going to do before actually running the upgrades. It isn't clear how to do a dry run with `cpan upgrade` – Stephen Ostermiller Jan 27 '18 at 09:42
-
I tried using this to update packages for imapsync, only to find that `cpan-outdated -p` didn't actually list any of the modules used by imapsync. Manually updating them with `cpanm` worked. – DustWolf Apr 21 '23 at 10:09
An easy way to upgrade all Perl packages (CPAN modules) is the following way:
cpan upgrade /(.*)/
cpan will recognize the regular expression like this and will update/upgrade all packages installed.

- 30,738
- 21
- 105
- 131

- 653
- 5
- 2
-
11Okay, this isn't as _cool_ as `cpanminus`, but at least you don't have to download anything to get this to work. – David W. Apr 26 '12 at 02:21
-
16For those having problems with this command; Try running cpan shell via `cpan`, and then run the `upgrade /(.*)/` in the cpan shell. – earthmeLon Feb 15 '16 at 17:43
For Strawberry Perl, try:
cpan -u

- 30,738
- 21
- 105
- 131

- 2,092
- 1
- 23
- 25
-
5For regular Perl too. From the man page: `-u Upgrade all installed modules. Blindly doing this can really break things, so keep a backup.` – Chloe Apr 04 '16 at 03:04
-