Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Understanding Perl / Brew Perl and Cpan on macOS

by feumw (Sexton)
on Apr 02, 2020 at 09:36 UTC ( [id://11114952]=perlquestion: print w/replies, xml ) Need Help??

feumw has asked for the wisdom of the Perl Monks concerning the following question:

The title might be a little weird but I couldn't sum up better what I want to know.

So I'm working on a macOS. As war as I know /usr/bin/perl is the default perl which comes with the OS. Some people say it's bad and you can't get full usage out of it so they prefer to install perl again via homebrew - The Missing Package Manager for macOS (or Linux).. No matter which perl (default=/usr/bin/perl / or homebrew=/usr/local/bin/perl is "active" for me cpan stays on the same location (/Users/myusername/.cpan). I double checked both with perl -MCPAN -e shell aswell.
How does this work? Does cpan install the Modules into it's own directories and no matter which perl is active, perl is just allowed to access those folders?

On Stackoverflow I found an article about cpan-vs-mcpan-perl saying:
cpan installs for the perl in the shebang (#!) line of the cpan file.
When someone has more than one perl installed on a machine, they sometimes run the wrong copy of cpan, and thus end up installing modules for the wrong instance of perl.
One solution to that would be to specify the full path to the correct cpan file.
perl -MCPAN -e shell is the other solution. It allows you to explicitly specify the install of perl for which you want the modules to be installed.
I'd have assumed I have different locations using perl -MCPAN -e shell.

Let's say I want to split my CPANs having one for the default and one for the homebrew perl. How can I do this?
And does reinstalling a new fresh and clean cpan mean just rm -rf /Users/myusername/.cpan?

I hope I can find some Wisdom here to clear up my minds. Thanks in advice.

Replies are listed 'Best First'.
Re: Understanding Perl / Brew Perl and Cpan on macOS
by kcott (Archbishop) on Apr 03, 2020 at 09:58 UTC

    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:

    • 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:

    #!/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

      "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

      I started using perlbrew and so far things look great for me. Thank you alot for your detailed explanations, Sir!
Re: Understanding Perl / Brew Perl and Cpan on macOS
by 1nickt (Canon) on Apr 02, 2020 at 10:27 UTC

    Hi, you want Perlbrew for Perl on MacOS. Homebrew for other packages.

    The way forward always starts with a minimal test.
      Installation worked fine. Don't have too much time to try out if everything works perfectly but I guess it does. I had a couple questions which I could anser myself while installation on the perlbrew website plus this guide on for centos.

        That's great. Very nice of you to follow up.

        I assume you're now going to be using cpanm for installing modules from CPAN, as recommended and facilitated by perlbrew ... if so, I urge installing App::cpanminus::reporter in each Perl version and contributing your test reports to the CPAN Testers service (by simply typing cpanm-reporter after you've installed a module or a group of them). It's a great and almost effortless way to give back to the amazing infrastructure that makes working with Perl (including different Perl versions on different OSes) so easy and enjoyable.

        Have fun!

        The way forward always starts with a minimal test.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11114952]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2024-05-25 23:57 GMT
Find Nodes?
    Voting Booth?

    No recent polls found