1

First of all am new to MAC.
Am facing similar kind of issue on Mac where its shipped with V5.28.0 but i have to use perl V5.18.2 for my application. Have installed perl 5.18.2 using perlbrew install 5.18.2 and the installation was successful.

Have two questions here

  1. Where are my default version and other version installed ? Is there any command to know them ? Have already tried checking echo $PATH but no use.

  2. How to set the default version to 5.18.2 ?

Regards
AVK

mihai
  • 37,072
  • 9
  • 60
  • 86
user288686
  • 135
  • 2
  • 11

2 Answers2

2

The default installation location is

/usr/bin/perl

But that might not be where it's located on MacOS. You can find out for sure by running the following:

perlbrew off
which perl

(Restarting the terminal will reactivate perlbrew.)


The build you installed is in a directory under the directory returned by the following:

printf -- "%s\n" "${PERLBREW_ROOT:-$HOME/perl5/perlbrew}/perls"

You can modify the PATH so that perl runs the desired build using

perlbrew switch <name>     # Changes it for this shell instance and those created later.
perlbrew use <name>        # Changes it for this shell instance only.

You can get the names to use from

perlbrew list

See Switching to the system Perl using perlbrew for switching to the system Perl.


Scripts need to have the correct perl specified on their shebang (#!) line. Scripts installed by the standard Perl module installers will have this set correctly, but you'll need to edit the shebang (#!) line of scripts you've installed manually.

ikegami
  • 367,544
  • 15
  • 269
  • 518
0

Another option (incompatible with perlbrew) is to use plenv. This lets you run different versions of perl for each directory. After installing with brew install plenv, you'd use it like so:

$ plenv install 5.18.2
$ cd project/needing/old/perl
$ echo "5.18.2" > .perl-version

Poof! Running perl in that directory or any of its subdirectories will use 5.18.2.

Note: if you run a perl script with ./script.pl, which has #!/usr/bin/perl, this should continue to use the perl installed at /usr/bin/perl. However, if the shebang line is /usr/bin/env perl, this should switch to the version specified by the .perl-version file.

Ashton Wiersdorf
  • 1,865
  • 12
  • 33
  • How does this answer any of the questions? They OP is already using perlbrew and they're asking how to use it along with other questions, none of which this answers. On top of that, using `/usr/bin/env perl` is a bad idea for the very reason you said: It will change what perl us used as `.perl-version` is changed, rather than using the one for which it was installed. – ikegami Nov 28 '18 at 06:10
  • @ikegami This is primarily for anyone else who runs across this question. I’ve needed to run lower versions of peel for certain applications on macOS, and this has been the best solution for me. (I’ve run perlbrew as well as plenv.) I hope someone else might find it useful. – Ashton Wiersdorf Nov 28 '18 at 15:04