1

I have installed ActivePerl 5.20.2 today on Mac OS X 10.9.5 Checking the version of perl in Terminal (perl -v) I see 5.20.2 So everything seems to be ok. But.. When I start my CGI scripts the script is running under built in perl (which is 5.16) (if using #!/usr/bin/perl). If I use #!/usr/local/ActivePerl5.20.2/bin/perl then it runs under 5.20.2 that is required.

The question is: is it somehow possible to change the directory for using in my scripts from #!/usr/local/ActivePerl5.20.2/bin/perl to simple and familiar #!/usr/bin/perl keeping running under ActivePerl instead of built in.

I need to override the system's default version with the new ActivePerl.

I would be appreciated for your detailed answers (with name of files and directories where they are located) if ones are to be changed to implement salvation.

Thanks!

Arsenii
  • 655
  • 1
  • 8
  • 20
  • 1
    Also, specifying the specific interpreter you want in your scripts is a ***feature***, not something to be avoided. – Sinan Ünür May 21 '15 at 20:19
  • 1
    It seems `#!/usr/local/ActivePerl5.20.2/bin/perl` is being found before `/usr/bin/perl` in your shell's `$PATH`. Can you set the $PATH in the environment running the CGI scripts? You could then place `/usr/local/ActivePerl5.20.2/bin/` earlier in the path and call `#!/usr/bin/env perl`. That *may* work but pointing at the specific version is best. – G. Cito May 21 '15 at 20:20
  • @SinanÜnür Thanks. It was typo (and copypasting with typo). My scripts, of course, have no typos in shebang lines ))) – Arsenii May 21 '15 at 20:22

2 Answers2

4

The question is: is it somehow possible to change the directory for using in my scripts from #!/usr/local/ActivePerl5.20.2/bin/perl to simple and familiar #!/usr/bin/perl keeping running under ActivePerl instead of built in.

Don't even try. That way lies damnation, not salvation. The ability to specify the specific interpreter that will handle your scripts is an important feature.

Instead, package your CGI script as a simple CPAN module. Then, install it using the familiar

$ /usr/local/ActivePerl5.20.2/bin/perl Makefile.PL
$ make install

routine. The shebang line will be automatically adjusted to reflect the perl that was used to build and install your package.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
3

First, instead of specifying a particular path to your Perl interpreter in your script:

#! /usr/local/ActivePerl5.20.2/bin/perl

or

#! /usr/bin/perl

Specify this:

#! /usr/bin/env perl

This will find the first executable Perl interpreter in your $PATH and then use that to execute your Perl script. This way, instead of having to change your program, you only have to change the $PATH variable.

Next time, take a look at PerlBrew for installing a different version of Perl. PerlBrew will allow you to install multiple versions of Perl all under user control, and let you select which version of Perl you'd like to use.

I also recommend to put /usr/local/bin as the first entry in your $PATH. Then, link the executables you want to run to that directory. You can use something like this to create your links:

for file in $/usr/local/ActivePerl5.20.2/bin/*
do
    basename=$(basename $file)
    ln -s "$file" "/usr/local/bin/$basename"
done

This way, all programs you want to execute are in the same directory which makes setting $PATH so much easier. I even put /usr/local/bin in before /usr/bin and /bin because I want to be able to override the system's default version.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • Thanks! Couldn't you tell me, please, how to define the $PATH variable? Is it that in .bash_profile in the user dir? Can you, please, show me a simple example? I have there now the next strings: PATH=/usr/local/ActivePerl-5.20/bin:$PATH PATH=/usr/local/ActivePerl-5.20/site/bin:$PATH export PATH – Arsenii May 21 '15 at 20:35
  • I would like to override the system's default version. That is what I want)) – Arsenii May 21 '15 at 20:42
  • 1
    You are forgetting that the OP is running CGI scripts. IMHO, it is not a good idea to to put `#!/usr/bin/env perl` in anything other than throwaway command line scripts. Far better to just package it with a `Makefile.PL`. Then, it does not matter what else is going on. The server gets to use the right `perl` every time. – Sinan Ünür May 21 '15 at 23:18