bulrush has asked for the wisdom of the Perl Monks concerning the following question:

Questions:

  1. How do I change the file at /usr/bin/perl to a link which executes $HOME/perl5/perlbrew/perls/perl-5.20.1/bin/perl? I.e. /usr/bin/perl should actually execute $HOME/perl5/perlbrew/perls/perl-5.20.1/bin/perl. This would be the easiest way for our other 4 users to automatically use the new Perl without me having to edit their PATH variable in their .cshrc.
  2. Do I need to change the owner or permissions of everything in $HOME/perl5/ so everyone can use the link?
  3. Will this new version of perl still use the system cpan modules?
  4. When I install new cpan modules using 'sudo cpanm Module::Name' will they still be installed to the system location with all the other modules?
  5. Can I keep my PERL5LIB set to this: 'setenv PERL5LIB /usr/lib/perl5/site_perl/5.8.8/auto:/usr/lib/perl5/site_perl/5.8.8'?
Thank you! You're all awesome!
EDIT1: Uh oh, it turns out I'm trying to use the 'ln $HOME/perl5/perlbrew/perls/perl-5.20.1/bin/perl /usr/bin/perl' and getting a "Invalid cross-device link" because my $HOME and /usr/bin are on different devices. Any advice to fix this?

Should I just make a shell script /usr/bin/perl which contains:

#!/bin/csh /export/home/chuck/perl5/perlbrew/perls/perl-5.20.1/bin/perl \!*
"\!*" is what I would type into the text editor to add all parameters to the perl command line when the shell script is called. Is that the right syntax for csh? Owner of /usr/bin/perl would have to be root with permissions a+rwx.
EDIT2: Question closed. Thanks I got this partially working, I am having some problems setting @INC, because I installed some CPAN modules and they are now in the new perl subdir. I'll make another question for that later.

Replies are listed 'Best First'.
Re: How to make symlink to new upgraded Perl?
by trippledubs (Deacon) on Jun 15, 2015 at 12:52 UTC

    Make your shebang line #!/usr/bin/env perl and then whichever perl is found first in your PATH environment variable will be the one used. perlbrew is its own beast. You put some perlbrew vars in your profile script, then perlbrew manages multiple perl installations. Try 'perlbrew available', 'perlbrew install 5.22.0' and then 'perlbrew switch 5.22.0'. If you did it right, `which perl`, should show that you are using one of the perlbrew managed perls.

    Each Perl installation by default will have a compiled @INC that refers to its own local installed modules. So generally if you don't mess around with it, every installation will maintain its own modules. The overall goal is that all you have to do is either use perlbrew to switch between perls or change your PATH variable. If you think that is a worthy goal you will not use /usr/bin/perl in your shebang lines, nor /home/perl5/perlbrew/perls/perl-5.20.1/bin/perl because that will tie you to that file.

    By default the ln command makes a hard link which is a pointer to the original file. You cannot span file systems with hard links. You probably want the '-s' option, which is a symbolic/soft link. Accomplishes same thing, but extra lookup. If you have two hard links to a file, deleting one will just decrease your link count by one. You will still be able to access using the other one. With two soft links, deleting the real file will cause the soft link to not work.

Re: How to make symlink to new upgraded Perl?
by u65 (Chaplain) on Jun 15, 2015 at 12:54 UTC

    How much trouble would it be to change all script shebang lines to:

    #!/usr/bin/env perl

    Then you could change the global user environment as appropriate.

Re: How to make symlink to new upgraded Perl?
by Anonymous Monk on Jun 15, 2015 at 12:09 UTC
    Dont mess with the system perl, means dont make that link, make another
      I knew generally you are right but this is a special case. The system perl was installed years ago by me, so me and 4 others are the only people who use this box, and we use only perl scripts that I made. So it shouldn't be an issue to change the link to point to the new perl.

        The vendor Perl belongs to the vendor. Maybe some Redhat scripts also use Perl (5.8.8) and expect some modules to be available. I recommend against replacing the vendor Perl with a different version.

Re: How to make symlink to new upgraded Perl?
by hippo (Archbishop) on Jun 15, 2015 at 13:49 UTC
    Uh oh, it turns out I'm trying to use the 'ln $HOME/perl5/perlbrew/perls/perl-5.20.1/bin/perl /usr/bin/perl' and getting a "Invalid cross-device link" because my $HOME and /usr/bin are on different devices. Any advice to fix this?

    Use a soft link for cross-device linking instead of a hard link (which is a technical impossibility in that case). ie:

    rm /usr/bin/perl; ln -s $HOME/perl5/perlbrew/perls/perl-5.20.1/bin/perl /usr/bin/perl

    Note that this only "solves" the problem quoted. The usual caveats raised in the other replies still stand.

      Again, don't replace the system Perl!!!!
      ln -s $HOME/perl5/perlbrew/perls/perl-5.20.1/bin/perl \ /usr/bin/perl-stable
      rm /usr/bin/perl ...

      This creates more problems, and doesn't solve any.