in reply to Understanding Perl / Brew Perl and Cpan on macOS
I used macOS (formerly Mac OS X) for about 9-10 years. I stopped using it in the latter half of last year: reasons were not Perl-related.
"... /usr/bin/perl is the default ... Some people say it's bad ..."
It's not so much that it's bad, per se. It's usually fairly up-to-date and fully functional. The problem is that it is the system Perl and is installed by Apple for their use. This has two major implications:
- If you install modules (which may update existing modules due to a new module's dependency requirements) you run the risk of affecting some part of the system in less than desirable ways.
- When you update macOS, Apple may simply wipe out the previous version of Perl and install a newer version. It's not just the core Perl that's removed; all modules you installed will be also deleted.
So, you should basically leave the system Perl alone and let Apple do whatever it wants with it.
I installed Perlbrew pretty much as soon as got the new machine. Over the decade that I used it, I installed many versions of Perl. I was able to switch between them when I wanted, which was often very handy for testing. I did not have problems with installing from CPAN; the cpan utility always matched the current Perl version in use; and installed modules only affected the current Perl version in use.
The shebang line I use for all scripts is:
That worked for all versions of Mac OS X and macOS that I had.
I see you've mentioned "perl -MCPAN -e shell" in a couple of places. The cpan utility does the same thing. See CPAN (the module) and cpan (the utility). Do note that there are some other things you can do beyond starting a CPAN shell; however, in 99% of cases, typing cpan is all I need.
"Let's say I want to split my CPANs ..."
No, that's not something you want to do. Always install modules for each version of Perl you are using. Never try to copy a module from one version of Perl to another.
"And does reinstalling a new fresh and clean cpan mean just rm -rf /Users/myusername/.cpan ?"
No, definitely don't do that either. When you switch between one version of Perl and another, Perlbrew takes care of the rest: it'll look after the $PATH environment variable, your .bashrc settings, and so on. In general, unless you know exactly what you're doing and why you're doing it, don't fiddle with things.
By the way, typing rm -rf followed by an absolute path is something I'd never do. It only takes a momentary distraction (the phone rings, you sneeze, or whatever) and you've accidentally hit Return after only typing rm -rf /Users/myusername. Here's what I'd normally do to remove an unwanted directory's contents and the directory itself:
$ cd /path/to/unwanted_dir $ rm -rf ./* $ cd .. $ rmdir unwanted_dir
I think that covers all of your points. Enjoy your Perl brewing. :-)