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

The Solaris, Perl 5.8 and use 5.005 post reminded me of a question I have. It's really about linking to the Perl executable on Linux and similar systems. I'm not any kind of expert and I'm unsure about the real-life differences on how links ( created with ln ) to executables are handled. Almost all of my perl scripts begin with this line:

#!/usr/bin/perl -w

but the actual location of the perl executable on most (but not all) my boxes is /usr/local/bin.

So here's my question: Is it preferred, just okay, or totally horrible if I put a symbolic (rather than hard) link in /usr/bin which points to /usr/local/bin/perl ? Is there a reason I can't, or shouldn't make it a symbolic link, rather than a hard link?

I'd like to make sure I have only one "perl" which runs, and it's always the latest version (if I want a specific version, I can call /usr/local/bin/perl5.6.1 or whatever). Since the current versions install into /usr/local/bin, I'd like to put a link in /usr/bin which points to the current version. If it's not obvious, I don't want to go through and edit all my old scripts.

This must be a common task and I want to do it right. Is there a preferred way to do it? Thanks.

Replies are listed 'Best First'.
Re: Linking to the perl executable
by Zaxo (Archbishop) on Mar 09, 2005 at 07:03 UTC

    The symlink is fine, a *nix standard way of doing that. That can also be used to provide a default perl (usually the latest) where all perls are installed with a version suffix to the same PREFIX:

    # ln -sf /usr/bin/perl-5.8.6 /usr/bin/perl #

    After Compline,
    Zaxo

      Excellent. Thanks! I just wasn't sure if a symlink in /usr/bin to /usr/local/bin/perl was treated different than a hardlink. This is cool and makes it easy to ensure linking to the current version.
        But please beware: many system utilities depend upon Perl; If your system comes with 5.005 installed, it usually resides in /usr/bin. Replacing /usr/bin/perl with another version (even when it resides in a different directory and you link to it) may break your system if not all system-installed modules are available of if system related programmes depend on bugs (or call them features) which are resolved in your Perl version.

        I advice you to test things thouroughly before applying this change to a production system

        Paul