in reply to Understanding Perl / Brew Perl and Cpan on macOS

G'day feumw,

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:

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:

#!/usr/bin/env perl

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. :-)

— Ken

Replies are listed 'Best First'.
Re^2: Understanding Perl / Brew Perl and Cpan on macOS
by marto (Cardinal) on Apr 03, 2020 at 11:34 UTC

    "The problem is that it is the system Perl and is installed by Apple for their use."

    Just an FYI, in future releases Perl (among others) won't be installed by default.

      G'day marto,

      Thanks for that piece of information. Since I dropped macOS usage, I haven't kept abreast of that type of news.

      My understanding is that Perlbrew requires Perl to be present for its initial installation. Subsequent work with Perlbrew — upgrading, installing new Perls, etc. — can utilise a Perl already installed by Perlbrew. I've used Perlbrew for a very long time and have always had some sort of system Perl to kickstart the process, this includes: macOS as just described; Cygwin on my current and past setups; and, Linux on my $work machine.

      I had a look at "Perl Download". From what it has there, it looks like ActiveState Perl might be the best way to install an initial Perl from which Perlbrew can be run. The Mac Pro that I previously had has been cannibalised to the extent of being completely non-operational; I have no way of running macOS at the present time.

      For future reference by those starting with macOS v10.15, or a later version, it would be helpful it someone could comment on the best way to start the Perlbrew process.

      — Ken

        Hey Ken, I'm not a Mac guy either, however rather than go down the AS route I think installing perl via brew would be better for the getting an initial version on the system, given that ActiveState now want you to have an account with them to download, and the version is old (5.28 at time of writing).

        If in future versions of MacOS Perlbrew no longer works, then I suspect Homebrew probably is the best place to get at least an initial replacement for the system perl after all.
Re^2: Understanding Perl / Brew Perl and Cpan on macOS
by feumw (Sexton) on Apr 06, 2020 at 04:39 UTC
    I started using perlbrew and so far things look great for me. Thank you alot for your detailed explanations, Sir!