0

I remember I have installed Perl::Rename, by using cpan -i File::Rename, and indeed I have $HOME/perl5/bin with rename and unsafe-rename executables there.

But when I try to use rename,

# Expected: Renames FooBar.txt to Foo_Bar.txt
# It worked for me in the past
rename 's/\s/_/' *.txt

...there is an error:

Can't locate File/Rename.pm in @INC (you may need to install the File::Rename module) (@INC contains: /Library/Perl/5.34/darwin-thread-multi-2level /Library/Perl/5.34 /Network/Library/Perl/5.34/darwin-thread-multi-2level /Network/Library/Perl/5.34 /Library/Perl/Updates/5.34.1 /System/Library/Perl/5.34/darwin-thread-multi-2level /System/Library/Perl/5.34 /System/Library/Perl/Extras/5.34/darwin-thread-multi-2level /System/Library/Perl/Extras/5.34) at ./rename line 4.
BEGIN failed--compilation aborted at ./rename line 4.

Then I tried to reinstall File::Rename, by using the same command, but then there is another error message, a very long one. Here is a part from the very end:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ERROR: Can't create '/Library/Perl/5.34/File'
mkdir /Library/Perl/5.34/File: Permission denied at /System/Library/Perl/5.34/ExtUtils/Install.pm line 470.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 at -e line 1.
make: *** [pure_site_install] Error 13
  RMBARKER/File-Rename-2.02.tar.gz
  /usr/bin/make install  -- NOT OK

What is goind on here?..

Perl itself is the one that is supplied with macOS. I didn't istall it.

2
  • What are the values of environment variables that start with $PERL, like $PERL5LIB, $PERL_LOCAL_LIB_ROOT, or $PERL_MM_OPT? Commented Mar 16 at 7:24
  • @choroba Each one of these three returns an empty string for me. I remember I messed up with my zsh config and removed what cpan added there to adjust $PATH - this is probably the very reason why the variables are emtpy currently. Commented Mar 16 at 8:31

1 Answer 1

2

Upon first running cpan as a non-superuser, and as you have chosen the local::lib approach when prompted, it will have told you something like:

local::lib is installed. You must now add the following environment variables
to your shell configuration files (or registry, if you are on Windows) and
then restart your command line shell and CPAN before installing modules:

PATH="/path/to/your/home/perl5/bin${PATH:+:${PATH}}"; export PATH;
PERL5LIB="/path/to/your/home/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
PERL_LOCAL_LIB_ROOT="/path/to/your/home/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
PERL_MB_OPT="--install_base \"/path/to/your/home/perl5\""; export PERL_MB_OPT;
PERL_MM_OPT="INSTALL_BASE=/path/to/your/home/perl5"; export PERL_MM_OPT;

Which you need to do for perl to know where to find the modules installed by cpan. cpan can also install system wide if run as root, though you may then prefer package installation methods that are either native to your system (apt, dnf... depending on the system) even if that may mean getting older versions of the perl module or better integrated or that you already use such as homebrew/macports on macos, to avoid having to maintain packages in yet another packaging system.

2
  • I know zsh configuration files (.zprofie, .zshenv, .zshrc) aren't scripts. But maybe it is possible (in a more or less straighforward way) to have a variable for the /path/to/your/home/perl5/ part, so that it will be easier to change it for all the five lines? Commented Mar 16 at 11:20
  • 1
    @jsx97, sure, I just copy-pasted the output of cpan here. Commented Mar 16 at 11:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.