3

I am on a Mac so of course I'm running into this huge problem with perl on the Mac where the OS is trying to protect me and it's a nightmare to install . The solution seems to be "make your own perl instead of using the one with the OS" so I've done that. I ran brew install perl and now I have this in my .bashrc

PATH="/Users/ericmueller/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/Users/ericmueller/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/Users/ericmueller/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/Users/ericmueller/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/Users/ericmueller/perl5"; export PERL_MM_OPT;
eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"
source ~/perl5/perlbrew/etc/bashrceval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"

Honestly, I have no idea what most of this is ;-) but it looks like I have my own perl in my folder and I see that I can run simple perl scripts so I guess all is good.

So now I want to install cpanminus and DBI.

I installed cpanminus (brew install cpanminus), without errors. But then when I run cpanm DBI it fails, and when I look at the log where it failed, I see this:

"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- DBI.bs blib/arch/auto/DBI/DBI.bs 644
"/usr/bin/perl" -p -e "s/~DRIVER~/Perl/g" ./Driver.xst > Perl.xsi
"/usr/bin/perl" "/System/Library/Perl/5.18/ExtUtils/xsubpp"  -typemap '/System/Library/Perl/5.18/ExtUtils/typemap' -typemap '/Users/ericmueller/.cpanm/work/1555346710.17160/DBI-1.642/typemap'  Perl.xs > Perl.xsc
mv Perl.xsc Perl.c
cc -c   -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -fstack-protector -Os   -DVERSION=\"1.642\" -DXS_VERSION=\"1.642\"  "-I/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE"  -W -Wall -Wpointer-arith -Wbad-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual -Wmissing-noreturn -Wno-unused-parameter Perl.c
In file included from Perl.xs:7:
./DBIXS.h:22:10: fatal error: 'EXTERN.h' file not found
#include <EXTERN.h>
         ^~~~~~~~~~
1 error generated.
make: *** [Perl.o] Error 1

This is totally the stupid Mac perl problem, and the issue appears to be that it's still trying to put the DBI library (or one of its dependencies) in /usr/bin/ which is a big no-no. Or maybe it's trying to use the system perl to do the installation, so that's also failing. I have my own perl5 installation in my home folder. That's where it should be putting things and working with them.

So if that is the issue (and I am really shitty at both perl and this kind of sysadmin stuff, so I'm not 100% sure!), how do I get cpanm to work with my perl in my home folder, instead of in /usr/bin/? I don't want ANYTHING to happen in /usr/bin/ since that is a non-starter!

** EDIT I removed everything but the PATH command from my bashrc, and now I get this when I run cpanm DBI

!
! Can't write to /Library/Perl/5.18 and /usr/local/bin: Installing modules to /Users/ericmueller/perl5
! To turn off this warning, you have to do one of the following:
!   - run me as a root or with --sudo option (to install to /Library/Perl/5.18 and /usr/local/bin)
!   - Configure local::lib in your existing shell to set PERL_MM_OPT etc.
!   - Install local::lib by running the following commands
!
!         cpanm --local-lib=~/perl5 local::lib && eval $(perl -I ~/perl5/lib/perl5/ -Mlocal::lib)
!
--> Working on DBI
Fetching http://www.cpan.org/authors/id/T/TI/TIMB/DBI-1.642.tar.gz ... OK
Configuring DBI-1.642 ... OK
Building and testing DBI-1.642 ... FAIL
! Installing DBI failed. See /Users/ericmueller/.cpanm/work/1555348167.22814/build.log for details. Retry with --force to force install it.

So the good news is that I am definitely using the cpanm that comes with my custom perl5 in my /Users folder. The bad news is, I'm still getting the exact same stupid problem.

Eric
  • 5,104
  • 10
  • 41
  • 70
  • 1) There's no point to using local::lib if you're using a locally-installed build of Perl. I wouldn't add any of the lines you added to your login script to my login script. – ikegami Apr 15 '19 at 17:05
  • 2) I don't know about `brew`, but `perlbrew` requires that I add something to my login script. I don't see that here? – ikegami Apr 15 '19 at 17:06
  • Ok. Should I cut all those lines from my .bashrc? - I really don't know what they all do. – Eric Apr 15 '19 at 17:06
  • 1
    3) You need to use the a `cpanm` that was installed using the `perl` you wish to use. – ikegami Apr 15 '19 at 17:06
  • Aha - using a cpanm that was installed with the perl in my home folder - how do I do that? Just find it in there? – Eric Apr 15 '19 at 17:07
  • 1
    Those lines do the same thing three times, and that thing is telling Perl to install modules in a non-default directory (and telling Perl to look there for modules). It should be perfectly fine and simpler to install in the default directory when using a locally-installed Perl. – ikegami Apr 15 '19 at 17:08
  • It looks like I am using the cpanm with that install: `which cpanm` gives me `/Users/ericmueller/perl5/bin/cpanm` – Eric Apr 15 '19 at 17:09
  • See comment (2). There should be something that places your `perl`'s `bin` first in the PATH. Once you install `cpanm` using your `perl`, it should be found. – ikegami Apr 15 '19 at 17:10
  • That's good. Double check `head -n 1 "$( which cpanm )"`. Should be your `perl` – ikegami Apr 15 '19 at 17:10
  • 4) The message you posted don't indicate that "it's still trying to put the DBI library (or one of its dependencies) in /usr/bin/", but it does indicate the system Perl is being used to install them, and that's no good. – ikegami Apr 15 '19 at 17:12
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/191861/discussion-between-eric-and-ikegami). – Eric Apr 15 '19 at 17:12
  • Small correction to what I said earlier: `source ~/perl5/perlbrew/etc/bashrceval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib=$HOME/perl5)"` should be `source ~/perl5/perlbrew/etc/bashrceval` (because the scripts takes no arguments), and you need to keep that to keep `perlbrew` working. – ikegami Apr 16 '19 at 11:41

1 Answers1

-1

yep ... MacOS Perl is something you should rather not touch.

yes ... You can do it.

but ... Common practice, https://perlbrew.pl

and ... Install some shinny perl

and ... follow the instructions on the website about cpanm

vanHoesel
  • 956
  • 9
  • 22