macosperlpathosx-mavericksactiveperl

How to use default path for ActivePerl 5.20 Mac OS X (/usr/bin/perl) instead of /usr/local/ActivePerl...?


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!


Solution

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